9 Cool Useful Command Prompt Tips You May Not Know

We do love Command Prompt, don’t we? If so, why not learning another set of tips and tricks that you may not know to get more out of it? Let’s take look at them.

Tip #1: F7

If you think using Doskey to check the command history is cool, this is even cooler. Simply press F7 and a history of the commands you have used in the same session pops up right in the middle.

Command Prompt - F7

Tip #2: Mode to adjust the size of CMD window

Very useful when the output characters extend beyond the 80 characters.

Syntax: mode [width], [height]

It’s hard to have a nice screenshot to demonstrate, but type in mode 120, 25 in the Command Prompt to see what happens.

Tip #3: Color to change the default color of CMD

Syntax: color

The color attr is specified by 2 hex digits, the first one presents to the background while the second one responses to the foreground. Each digit can be found by simply typing color /?

Command Prompt - color fc

Tip #4: Tree to show off the folder structure

Syntax: Tree [drive:][path] [/F] [/A]

By default, it graphically displays the folder structure of a drive or folder. The switch /F will list the files in addition to each folder.

Command Prompt - tree

If you want to output the structure to a text file, use /A switch along with the > switch. For example, the following command outputs the structure to a text file named structure.txt

c:\>tree /a d:\users\s184 > d:\temp\structure.txt

image

Bonus tip: you can also export a Tree view of a specific folder right in File Explorer.

Tip #5: RD to completely delete a folder

Syntax: RD [/S] [/Q] [drive:]path

By default, it only removes a folder that is empty. With a switch /S, you can completely delete a folder that still has files and subfolders. It’s extremely useful when you want to delete folders while you are at the recovery mode with no GUI.

Tip #6: Run multiple commands at once

With “&&” to separate, you can run multiple commands at once from one line. The commands run sequentially from left to right and it breaks if any of the commands fails.

Simple but useless example:

c:\>color fc && dir

Tip #7: Tasklist to display the running processes

It not only lists all running processes on the local system but also displays on a remote computer as well.  There are a lot of good use of it. Be sure to use Tasklist /? to find out more. Here are a few good uses of them.

The switch /SVC to list the tasks with services that host them.

Command Prompt - tasklist #1

The switch /FO is useful when outputting the results in a txt file.

Command Prompt - tasklist #2

Pipe with Find to narrow down the result.

Command Prompt - tasklist #3

Tip #8: Tab to Auto-complete

To save your time on typing the whole command, simply press Tab key to cycle through all the files and folders in the current folder. If you type a few keys and then start pressing Tab, it will cycle through files and folders that match what you have just typed. That’s pretty cool.

command-prompt-trick-autocomplete

Tip #9: Drag & Drop

If you are tired of typing the full path of a file or folder, this trick is going to help you greatly.

command-prompt-trick-drag-and-drop

Exactly, drag any file or folder into the Command Prompt and it will translate into that file or folder’s full path.

Thanks to MakeUseOf for inspiring the ideas for both tip #8 and #9

Bonus tip

Before we end here, here is a bonus tip for those who read all the way here. There are 4 command prompt alternatives available for free if you feel that the built-in CMD isn’t good enough.

And that’s it for the day. More to come if you find them useful.

Kent Chen

Microsoft MVP, IT Professional, Developer, Geek, and the co-founder of Next of Windows.

Last updated: 11/25/2015

Posted in: Tips & Tricks
Discover more: , ,

Leave a Reply

Notify of
avatar
David
Guest

Output the result from any command line to the clipboard and past to wherever needed:
Example using tree from # 4 above:

tree | clip

Kent Chen
Guest

Thanks. It’s a nice use of clipboard trick.

BlameJim
Guest
Re #6: The syntax with the ‘&&’ runs the second command only if the first one succeeds. To always run the second command, use a single ampersand. To run the 2nd command only if the first one fails, use double bars: ‘||’. These can be chained together as well. For example, here is a very simple demonstration on how to check for a directory, and report whether or not it was found: DIR xyzzy && ECHO Found the directory || ECHO Directory doesn’t exist. Also, steps can be grouped with parenthesis: DIR xyzzy && ECHO Found the directory || (ECHO… Read more »
jwh_at_abb
Guest

I love the F7 command history window but it’s too narrow. Is there a way to adjust the width?

wpDiscuz