4 Useful Windows Command Prompt Tricks To Know

Using the Windows command prompt can often be quicker for certain tasks like creating files and redirecting command output.

cmd in Windows run box

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
copy con command to make files through Windows command prompt

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.

files created through the Windows command prompt will always be accessible through File Explorer too

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.

Show contents of a text file with the type command

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

redirect output in Windows command prompt

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

Append redirected output in Windows command prompt

Note: The > redirection overwrites any existing content of the file.

Overwrite previous contents of redirection in the Windows command prompt

4. Quickly reuse recently typed commands:

View the commands typed in previously by pressing the F7 key.

Reuse previously typed Windows commands

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.

Leave a Comment