Most of the function keys (F1 through F9) serve a function in the Command Prompt:
When you want to see every single command you’ve typed since the beginning of the session, you can just use this command:
doskey /history
Doskey is a utility provided by Microsoft with several functions, one of which is this history of commands. It’s basically the same thing as pressing F7, except you can save, feed, or manipulate the output elsewhere. See Tips #7 to #9 further down in this article.
If you need to recall a previous command, either to repeat it or modify it, all you have to do is press the Up Arrow key. Keep pressing it to cycle commands, starting with the most recent.
This is functionally the same as pressing F8 except for one difference: Up Arrow places your cursor at the end of the command while F8 places your cursor at the start of the command.
Suppose you need to run a dozen commands in sequence but each command is a time-intensive task. You don’t want to sit at your computer and wait for each one to finish just so you can type in the next command, do you?
Instead, chain multiple commands together using &&:
cd C: && echo I'm here!
The commands are run in the order you entered them, starting from the left and moving to the right, and commands aren’t executed until the previous one finishes.
If you ever type a command and it takes a lot longer to complete than you expect, you can just press Ctrl + C to cancel and stop right away. This also comes in handy when you run an always-on program and need to end it.
Most Windows commands produce output to the screen, but sometimes they produce a lot of output to the screen — so much so that it instantly scrolls off the screen and disappears, even if you try to scroll up! Here’s what you can do:
[command with output] | more
The more command displays the output like normal, but it stops when the screen fills. At that point, you can press Space to continue the output by another page, or you can press Enter to continue the output by a single line.
If the output of a command is verbose and you need to find a particular line or instance of a word, you can filter the output like so:
[command with output] | find "query"
For example, suppose you run a diagnostic utility that prints out all of the system errors accumulated over the past year. If you just want to narrow it down to a certain type of error, you could filter the output by querying for it.
The find filter applies on a line by line basis, so it’ll return all lines that include the query text.
Let’s say you need help troubleshooting an issue and Mr. Windows Wiz asks you to run a particular command and copy/paste the results to him. With how finicky the Command Prompt can be, simply highlighting and copying can be a pain in the neck. Instead, do this:
[command with output] | clip
This feeds the command output directly to your clipboard. Now you can just Ctrl + V it wherever you want. This will overwrite your clipboard’s current contents, so be careful!
If your intention is to save the output of a command to a file, you could use the clip method above… or you could skip the middle step and send it directly to a file:
[command with output] > filename.txt
This creates a file named filename.txt in the current location of the Command Prompt, then pastes all of the output inside, then saves. If the file already exists, it will overwrite everything. If you want to save it elsewhere, type the full path (e.g. C:\folder\filename.txt).
Don’t want to overwrite? You can instead append the output to the end of an existing file:
[command with output] >> existingfile.txt
If you’re working with files in a deeply nested directory and need their full pathnames for a command, you have a few options. You can type them out manually. You can copy the path from the address bar of File Explorer, then type the filename. Or you can just drag and drop the file right into Command Prompt!
For some reason, this only works in normal Command Prompts. It does NOT work in elevated Command Prompts (i.e. when the Command Prompt is launched as Admin). Learn more about opening elevated Command Prompts using the Windows Power User Menu.
If you want to visualize the layout and structure of a folder that has tons of files and subfolders, use the tree command. It’s extremely simple to use and easy to understand, and it can be customized with parameters to tweak the visualization:
It shows the structure of the current folder, but you can view the structure of another folder by typing its full path as a parameter. By default, the command only shows folders, but you can also view files by adding the tree /F parameter.
For massive folders, you may want to output to a file for easier viewing.
For times when you need to type out full path names by hand, the Tab key will save you so much time. As you’re typing the path name, Tab will autocomplete to the closest matching folder or file. If multiple matches exist, keep pressing Tab to cycle through them.
For example, if I type C:\Us and then press Tab, it turns into C:\Users. I can continue typing until it becomes C:\Users\J, then press Tab to turn it into C:\Users\Joel.
It’s particularly useful when you’re in a folder and have a sense of what the next folder is called, but don’t know it fully. Just enter the first few letters and hit Tab. Easy!
Don’t like the size of the Command Prompt window? You can change it in the settings, but why go there when you can do it right from the command line?
mode [COLUMNS],[ROWS]
For example, if you want the Command Prompt to be 120 characters wide and 40 characters tall, just type mode 120,40 and it will instantly resize. Note that this wipes all of the text so don’t do it if you have output you still need.
If you have a lot of Command Prompt-only work to do and want to turn it into a distraction-free space, or if you just want to emulate the feel of old-school terminals, you can maximize it with a single keyboard combination: Alt + Enter.
This one isn’t so much a Command Prompt trick as it is a nifty quasi-Easter Egg maintained by a third party, but you can actually watch the entirety of Star Wars Episode IV right within Command Prompt. The catch? Everything is drawn using ASCII characters!
In Windows 10, you’ll have to enable Telnet because the telnet command is available in Command Prompt. To enable Telnet in Windows 10:
Now in Command Prompt, type this:
telnet towel.blinkenlights.nl
That’s it! Sit back and enjoy command prompt Star Wars.