Using the Windows command prompt can often be quicker for certain tasks like creating files and redirecting command output.
Although it does not get as much spotlight as the Linux command-line, here are some useful Windows command prompt tricks that you should know.
1. Create files:
Do you know that you can directly create files through the Windows command prompt? Use the copy con command for that.
Example: To create a file named Hello.txt from the command prompt, the command would be:
copy con Hello.txt
This will open a blank space for you to type in the file contents. When done, hit Ctrl+C to save and exit to create and save the file. It will also be available through File Explorer.
This is a useful command to quickly create small text files.
2. Display contents of text files:
You can directly view the contents of a text file from the Windows command prompt. The type command accomplishes this.
Example: To view the contents of a text file named Hello.txt, the command would be:
type Hello.txt
It will show the text file contents.
3. Redirect command output:
Redirect the output of commands to a file using the command prompt.
This is through the > and >> redirection.
Example: Redirect the output of the dir command to a text file named File.txt.
dir > File.txt
The >> redirection appends to the existing content and does not overwrite the previous content.
Example: Redirect the output of the ver command to append to the already existing contents of File.txt
ver >> File.txt
Note: The > redirection overwrites any existing content of the file.
4. Quickly reuse recently typed commands:
View the commands typed in previously by pressing the F7 key.
This displays the previous commands, use the arrow keys to navigate through them and hit Enter to execute them again.
Pretty cool.
These tricks can be a time-saver when working with the Windows command prompt. Do try them out.