Windows Command Line Top Secret
Copy and paste from/to the command line
Click on the icon in the title bar and choose Edit > Mark. Now, drag over the area you want to copy, hit Enter and the text is copied to the clipboard. Similarly, you can click on the icon in the title bar and choose Paste to paste the text you already have on the clipboard. You can also do this by right-clicking inside the command prompt window
F7 for command line history
Hit F7 and you will get a complete list of commands that you executed. Use the arrow keys to highlight the command you want to run again or just hit the number key corresponding to the command that you want to execute.
History keys
Use F1 to paste the previous command one character at a time, F2 (followed by a number) to paste the previous command up to the said number and F3 to paste the previous command.
Run multiple commands
You can run multiple command by separating them with &&. Note that this doesn’t run the commands simultaneously. Instead, the command towards the left is run first and if it completes successfully then the second command will run. If the first command fails, then the second command will not run
Filter command output
If you are only interested in part of command output and don’t want to spend time scanning the entire output, you can pass the output over to the find command. eg use tasklist | find “firefox” to only list the entry for Firefox if it is running.
Sleep or pause for some time
If you have ever written a batch file and wanted to wait for a period of time before you start executing the next command, you might have been amazed to find the “sleep” command missing. You can however hack yourself a sleep command using ping! Use ping -n 5 127.0.0.1 > NUL 2>&1 to wait for 5 seconds. Be warned that the timing would not be exact so don’t just bet your life on it.
Other Tips
- In place of find, check out findstr. It has much more robust filtering capabilities including regular expressions. http://technet.microsoft.com/en-us/library/bb490907.aspx
- Use the tab key when using cd command. It’ll cycle through the available directories. You can provide a starting point such as the initial letter to narrow down the list. The tab key will also allow you to select a filename in the same way
- use “dir > filename.txt” to print the contents of the actual folder into a text file. Good to make lists of folder’s contents.. the “filename.txt” doesn’t have to end in “.txt” but it’s convenient to open later. use “dir > filename.txt /s” to include all subfolders
- if you use &&, the command after the && only runs if the command before completes without error, which is what you often want. If you want the second command to run no matter what happens with the first command, use a single &.
OK, here’s where it gets real fun – you can use || to run the second command only if the first command causes an error.
Then it gets even more fun – you can chain these together!
A simple example:
DIR xyzzy && Echo Found it! || Echo It's not there.
This will run the commandDIR xyzzy
If xyzzy exists, then “Found it!” will be displayed
If xyzzy doesn’t exist, then “It’s not there.” will be displayed.
Think you know some more tricks? Have a command line tip to share? Sound off in the comments and let us know!

