The Best Command Prompt Tricks and Tips
Whatsapp Pinterest
Advertisement

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.

Unlock the "100+ Essential Windows CMD Commands" cheat sheet now!

This will sign you up to our newsletter

Enter your Email

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 /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 10 Neglected Windows Superpowers & How to Access Them 10 Neglected Windows Superpowers & How to Access Them With all its nooks and crannies, not even the most die-hard Windows fans have explored all its complex features. We have compiled those hidden Windows tips and tricks we think anyone will appreciate. Read More .

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.

More Command Prompt Tricks Worth Knowing

To really get comfortable with the command line, you should know these essential Command Prompt commands Essential Windows CMD Commands You Should Know Essential Windows CMD Commands You Should Know The bleak interface of the command prompt is your gateway to advanced Windows tools. We show you essential CMD commands that will let you access them. Read More . Is that too much to digest? Start with the most important Command Prompt commands 15 CMD Commands Every Windows User Should Know 15 CMD Commands Every Windows User Should Know The command prompt is still a powerful Windows tool. Here are the most useful CMD commands every Windows user needs to know. Read More instead, then work your way up afterward.

You should also get acquainted with these tips for mastering the Command Prompt How to Master the Command Prompt in Windows 10 How to Master the Command Prompt in Windows 10 This article makes the Windows 10 Command Prompt approachable and way more useful. Learn how to run multiple commands, get help on any command, and more. Read More . 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 7 Common Tasks The Windows Command Prompt Makes Quick & Easy 7 Common Tasks The Windows Command Prompt Makes Quick & Easy Don't let the command prompt intimidate you. It's simpler and more useful than you expect. You might be surprised by what you can accomplish with just a few keystrokes. Read More .

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

Explore more about: Command Prompt, Keyboard Shortcuts, Windows Tricks.

Enjoyed this article? Stay informed by joining our newsletter!

Enter your Email

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Gogu
    March 29, 2018 at 5:05 am

    the most used commands from windows used by linux users :))))
    control userpasswords2
    powercfg -h off
    sfc /scannow
    netsh winsock reset
    DISKPART remove letter -D (when remove letter from partition recovery)
    etc

  2. bill
    December 26, 2017 at 6:22 pm

    since the CMD prompt is replaced by PowerShell in W10 now, this is a little late for the party. How about updating for PowerShell?

    • Mike
      March 29, 2018 at 2:57 am

      Funny. I still have command prompt in my Windows 10. And being old school, really old school (My first computer course used punch cards), I still use command prompt and bat files.

    • Ian Hart
      April 3, 2018 at 12:25 pm

      Good point, fortunately, a lot of the CMD's still apply in Powershell

  3. Lee J
    December 24, 2017 at 1:38 am

    I use command prompt to 'Ping' websites that timeout before they load in the browser to see how many packets got dropped before it timed out

  4. Randy Stegbauer
    December 20, 2017 at 2:21 pm

    Thanks for mentioning the "clip" command! I've been using DOS for decades and didn't know about that!

  5. Owen
    December 20, 2017 at 10:05 am

    PowerShell does everything the command line does and way more? If you're learning, why would you ever start by going backwards??

    • trvth defender
      December 24, 2017 at 8:47 pm

      1. You will be glad to know that there is an alternative if for some reason PowerShell is unavailable or corrupt.
      B. The more you know about a system, the more competent a programmer or operator you become.
      III. Expands your ability to participate in discussions where the command line and its prompts are used as examples to explain other concepts

  6. V-Ger
    December 19, 2017 at 8:55 pm

    sudo apt-get uninstall windows & apt-get install linux

    • Adwait Thattey
      December 20, 2017 at 5:44 am

      ???

      • Randy Stegbauer
        December 20, 2017 at 2:23 pm

        Uninstall Windows and then install Linux. He's trying to be funny.

        • V-Ger
          December 20, 2017 at 10:33 pm

          Serious as breathing.. Or water

    • dragonmouth
      December 20, 2017 at 2:17 pm

      ROTFLMAO!!!

      That's a good one.

  7. Jonathan
    December 19, 2017 at 8:15 am

    I would also recommend anybody who uses the command prompt often on Windows use cmder.

    http://cmder.net/

    • Fred
      December 22, 2017 at 12:04 pm

      Thanks for proposing an alternative. I have been using console2, an improvement over console, but it has some drawbacks.

  8. Nav
    December 19, 2017 at 2:19 am

    Ridiculous argument to stick with command over Powershell: "the chief one being that PowerShell is more advanced and suited for power users."

    That's not even remotely true. You can deter yourself from anything with that way of thinking.