Include clear command in cmd

I know that cls is used to clear the screen in cmd, as clear command not available on cmd, being already used to bash, how can I add clear command in cmd to clear the screen?

2 Answers

How can I add clear command in cmd to clear the screen?

Option 1 - Use a batch file (clear.cmd):

@cls

Place clear.cmd somewhere in your PATH.


Option 2 - Use doskey:

doskey clear=cls

Notes:

  • doskey macros cannot be used within a batch file (only from the command line), so go for Option 1 if you want to be able to use clear in a batch file.

Further Reading

2

Apart from setting alias by doskey which is stored only in the current session, meaning it will go out on exit, and creating and moving clear.cmd or clear.bat to %SystemRoot% or %Windir% to run them directly without typing their path, which are usually located at C:\Windows\ path, you can press Ctrl+L to clear the screen which is consistent (I hope) in both Linux and Windows.

The default extensions (to omit when writing the full name of the file) are stored in PATHEXT variable (check them by issuing echo %pathext%). This is an environment variable meaning it is permanently defined, and always there for you to refer. You can set it permanently by setx (as setx %pathext%;.new which will keep the previous extension and add the new appending to the already existing ones).

The default path for executables (runnable files) to refer to is stored at PATH variable (echo %path% or path command).

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like