Search This Blog

Best Command Prompt Tricks

20 Cool Command Line Tricks for Windows and macOS


Best Command Prompt Tricks

The Windows Command Prompt tool, and many of its commands, might seem boring or even relatively useless at first glance, but as anyone who has ever used the Command Prompt very often can tell you, there's much to love!

These Command Prompt tricks will get you excited about many of the mundane-sounding Command Prompt commands like telnet, tree, or robocopy—okay, robocopy sounds pretty cool.

Some of these Command Prompt tricks are special features or fun uses for the Command Prompt itself, while others are just neat or relatively unknown things you can do with certain CMD commands.

Use Ctrl+C to Abort a Command

Photo of a computer keyboard

Just about any command can be stopped in its tracks with the abort command: Ctrl+C.

If you haven't actually executed a command, you can just backspace and erase what you've typed, but if you've already executed it then you can do a Ctrl+C to stop it.

It isn't a magic wand and it can't undo things that aren't undoable, like a partially complete format command.

However, for things like the dir command that seem to go on forever or questions you're asked at the prompt that you don't know the answer to, the abort command is an excellent Command Prompt trick to know.

View a Command's Results One Page (or Line) at a Time

DIR Command with More


Ever run a command, like the dir command, that produces so much information on the screen that it's almost useless?

One way to manage this info dump is to execute the command in a special way so whatever information is generated is shown to you one page, or one line, at a time.

Just type the command, the dir command for example, and then follow it with the pipe character and then the more command.

For example, executing dir /s | more will generate the thousands of lines of results that you expect from the dir command, but the more command will pause each page of results with -- More -- at the bottom of the page, indicating that the command is not done running.

Just press the spacebar to advance by page or press Enter to advance one line at a time.

Run Command Prompt as an Administrator Automatically

Command Prompt run as administrator option


Many commands require that you execute them from an elevated Command Prompt in Windows—in other words, execute them from a Command Prompt that's run as an administrator.

You can always right-click on any Command Prompt shortcut and choose Run as administrator but creating a shortcut to do the same thing can be a huge timesaver if you're a frequent Command Prompt power user.

To complete this trick, just create a Command Prompt shortcut on the desktop, enter the shortcut's properties and then select the Run as administrator box located in the Advanced button on the Shortcut tab.



Become a Command Prompt Power User With Function Keys

Illustration of an F7 key on a keyboard


The fact that the function keys actually do something in the Command Prompt is maybe one of the best kept secrets about the tool:

  • F1: Pastes the last executed command (character by character)
  • F2: Pastes the last executed command (up to the entered character)
  • F3: Pastes the last executed command
  • F4: Deletes current prompt text up to the entered character
  • F5: Pastes recently executed commands (does not cycle)
  • F6: Pastes ^Z to the prompt
  • F7: Displays a selectable list of previously executed commands
  • F8: Pastes recently executed commands (cycles)
  • F9: Asks for the number of the command from the F7 list to paste

Change the Prompt Text

prompt command to show the Windows version in Command Prompt for Windows 10

Did you know that the prompt itself in the Command Prompt is completely customizable thanks to the prompt command? It is, and when we say customizable, we mean really customizable.

Instead of C:\>, you can set the prompt to any text you want, have it include the time, the current drive, the Windows version number (like in this example image), you name it.

One useful example is prompt $m$p$g, which will show the full path of a mapped drive, alongside the drive letter. 

You can always execute prompt alone, without options, to return it to its sometimes boring default.



Get Help for Any Command

Photo of a red HELP key on a white computer keyboard

The help command does not provide help for every Command Prompt command.

However, any command can be suffixed with the /? option, usually called the help switch, to display detailed information about the command's syntax and often times even some examples.

The help switch may not be the coolest Command Prompt trick you've ever heard of, but it's hard to disagree that it's one of the more useful.

Neither the help command nor the help switch offer much in the way of explaining how to interpret the syntax. See How to Read Command Syntax if you need help with that.


Save a Command's Output to a File

Picture of the output of an instance of the systeminfo command


An incredibly useful Command Prompt trick is the use of redirection operators, specifically the > and >> operators.

These little characters let you redirect the output of a command to a text file, giving you a saved version of whatever data the command produced in the Command Prompt window.

For example, let's say you're about to post a computer problem to an online forum and you want to provide really accurate information about your computer. An easy way to do that would be to use the systeminfo command with a redirection operator.

For example, you might execute systeminfo > c:\mycomputerinfo.txt to save the information provided by the systeminfo command to that file. You could then attach the file to your forum post.

See How to Redirect Command Output to a File for more examples and a more in-depth explanation of how to use redirection operators.



View a Drive's Entire Directory Structure

tree command in a command prompt


One of the neatest little commands is the tree command. With tree, you can create a kind of map of the directories on any of your computer's drives.

Execute tree from any directory to see the folder structure under that directory.

With so much information created with this command, it's probably a good idea to export the results of tree to a file so you can actually look through it.



Customize the Command Prompt Title Bar Text

custom title bar on a Command Prompt window


Tired of that Command Prompt title bar text? No problem, just use the title command to change it to say whatever you like.

For example, let's say your name is Maria Smith, and you want to express your ownership of the Command Prompt. Execute this and the title bar will change immediately:


title Property of Maria Smith

The change won't stick, so the next time you open Command Prompt the title bar will be back to normal.

The title command is usually used to help give a custom appearance in script files and batch files—not that titling it with your name isn't a good idea!



Copy Text From the Command Prompt

Mark Feature in Command Prompt


Copying from the Command Prompt isn't as easy as copying from other programs, which is part of the reason why saving a command's output to a file, which you learned about a few tricks back, is so handy.

However, what if you do just want to copy a short section of text to the clipboard? It's not too hard but it's not very intuitive either:

  1. Right-click anywhere in the Command Prompt window and choose Mark.
  2. Highlight with your left mouse button whatever you'd like to copy.
  3. Press Enter or right-click once.

Now you can paste that information anywhere, just like you paste other text.

Post a Comment

0 Comments