The Best Command Prompt Tricks and Tips

The Best Command Prompt Tricks and Tips


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 /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.

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

Paginated Command Prompt output

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"

Filtered Command Prompt output

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:

Viewing folder structure in Command Prompt

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?

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.

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!

Watching Command Prompt Star Wars

In Windows 10, you’ll have to enable Telnet because the telnet command is available in Command Prompt. To enable Telnet in Windows 10:

  1. In the Start Menu, search for turn windows, then select Turn Windows features on or off in the results.
  2. Scroll down to Telnet Client and enable the checkbox.
  3. Click OK.

Now in Command Prompt, type this:

telnet towel.blinkenlights.nl

That’s it! Sit back and enjoy command prompt Star Wars.


    • Related Articles

    • 7 Common Tasks The Windows Command Prompt Makes Quick & Easy

      https://www.makeuseof.com/tag/7-common-tasks-windows-command-prompt-makes-quick-easy/ Run Any Program Easily Quick program access is important for productivity. Some of us have taskbars and start menus overflowing with shortcut icons. It’s not an ...
    • 7 tips to keep your Windows PC protected against malware

      https://m.windowscentral.com/how-to-keep-your-windows-pc-protected-against-malware Here are the best tips every Windows user should know to protect their computers and data against malware attacks. The internet has already become part of our daily ...
    • 7 best ways to free up hard drive space on Windows 10

      https://www.windowscentral.com/best-7-ways-free-hard-drive-space-windows-10 Although drives are only getting bigger and prices keep coming down, we keep running low on space on our Windows 10 devices as we continue to download tons of files from the ...
    • Excel out of Memory Error

      Method 1:  Delete the items from temporary folder and see if it helps. Hold Windows key + R. Copy and paste  or type the following command in the Open box, and then press Enter           %temp% Windows Explorer opens in the Temporary folder > Press ...
    • Add File Deletion Confirmation Dialog

      When the delete confirmation prompt is enabled and working, you will see a confirmation dialog asking “Are you sure you want to move these files to Recycle Bin?” even if you try to move the file to the Recycle Bin. Many users like to see a ...