Microsoft wants users to move over from Command Prompt to PowerShell, but there are good reasons not to, the chief one being that PowerShell is more advanced and suited for power users. Command Prompt remains the better option for everyday users. Learn more in our overview of differences between Command Prompt and PowerShell.
But just because Command Prompt is simpler doesn’t mean it’s primitive. You’ll find so many awesome Command Prompt tricks and tips that can make your life a lot easier, especially if you use the interface on a regular (or even semi-regular) basis. Here are some of our favorites.
1. Learn the Function Key Shortcuts
Most of the function keys (F1 through F9) serve a function in the Command Prompt:
- F1: Retypes the last used command, character by character per press.
- F2: Asks for a character, then retypes the last used command up to the first occurrence of that character.
- F3: Completely retypes the last used command.
- F4: Asks for a character, then deletes all characters in the current command, starting from the cursor position up to the first occurrence of the asked character.
- F5: Completely retypes previously used commands, but does not cycle.
- F6: Types ^Z into the current command.
- F7: Presents a menu of previously used commands.
- F8: Completely retypes previously used commands, does cycle.
- F9: Completely retypes a previously used command, corresponding to the number in the menu presented by F7.
2. View Command History
When you want to see every single command you’ve typed since the beginning of the session, you can just use this command:
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.
3. Repeat a Previous Command
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.
4. Run Multiple Commands at Once
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.
5. Cancel a Running Command
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.
6. View Command Output, Page by Page
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.
7. Filter the Output of a Command
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.
8. Copy the Output of a Command
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!
9. Save the Output of a Command
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
10. Drag and Drop Files
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.
11. View the Structure of Any Folder
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.
12. Autocomplete File and Folder Names
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!
13. Change the Window Size
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?
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.
14. Switch to Fullscreen Mode
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.
15. Watch Command Prompt Star Wars
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:
- In the Start Menu, search for turn windows, then select Turn Windows features on or off in the results.
- Scroll down to Telnet Client and enable the checkbox.
- Click OK.
Now in Command Prompt, type this:
That’s it! Sit back and enjoy command prompt Star Wars.
More Command Prompt Tricks Worth Knowing
To really get comfortable with the command line, you should know these essential Command Prompt commands. Is that too much to digest? Start with the most important Command Prompt commands instead, then work your way up afterward.
You should also get acquainted with these tips for mastering the Command Prompt. And if you aren’t really sure why you need the command line at all, here are some common tasks made easier by the Command Prompt.
What do you use the Command Prompt for? What are your favorite Command Prompt tricks? Let us know down in the comments below!
Image Credit: ARTIST/Depositphotos [Broken Link Removed]