Windows Command Line (CMD) Tips & Tricks
Command Prompt - CMD Tricks & Hacks
The command line (cmd) is very much effective and efficient at completing a myriad of tasks, in many cases with just a few commands. You might not know however a number of tricks and hacks you can use in the command prompt to take your efficiency and productivity to another level as well as impress your friends or family. Luckily for you we have compiled this short list of what we believe are the top 10 most useful tools, commands as well as tips & tricks you can use on the command prompt (cmd).
#1 Directory Structure
The tree command can make it very easy for you to locate files using the command prompt.
You can view how your directory is structured and where every file is located with the tree command.
Upon typing tree in your command prompt you can see a list of every file in your correct directory as well as every sub-directory.
You can also type tree followed by the name of your drive to view your entire computers file structure.
It might take a while for this to complete, depending on the size of your drive.
#2 Abort a Command
Commands like cipher or tree can take a quite a long time to complete. You occasionally might want to cancel the operation. To do that, simply press:
Control + C
A stubborn command might refuse to close with control + c, in which case press:
Control + Z
Which will force the command to stop.
#3 Command History
Apart from using the arrow keys, which only display your previous commands one by one you can type:
To view your entire command history. If having to type a command every time you have you want to view your history sounds like a chore, you can simply press:
In your keyboard and a window with your previous commands will show up. Use the arrow keys in your keyboard to navigate through all the commands and press enter to re-type the selected command
#4 Function Keys
Apart from using F7 to view your entire command history, there are a number of other function keys which you can use as well. Here is the full list:
- F1 – Pastes the letters of the last command, one at a time.
- F2 – Asks “Enter the char to copy up to” and pastes the previous command up to the selected character.
- F3 – Enters the last command.
- F4 – Asks “Enter the char to delete up to” and deletes every character up to the selected character (requires that the cursor is placed before that character).
- F5 – Types your previous commands one by one.
- F6 – Types Control + Z
- F7 – Displays your command history.
- F8 – Cycles trough your previous commands.
- F9 – Asks “Enter command number” and pastes the selected command from your history.
#5 Auto Complete
Typing lengthy commands can get quickly tiresome. Luckily the command line can automatically complete commands for you. For example lets say we want to navigate to a folder that is located in our current directory, lets first type cd and then press:
We can keep pressing tab to cycle through all the folders in this directory. Auto completion works on all sorts of commands and is a huge time saver.
#6 Drag and Drop Path Names
When using the command prompt you are often required to enter long paths to files or folders and while auto completion makes it a lot easier, there is a much better solution.
Simply open the folder in windows explorer and drag and drop it into the command line, its full path will immediately be shown.
#7 Manage Tasks
You can manage running tasks directly from the command line with tasklist and taskkill.
Upon typing tasklist a list of every running process is displayed along with its id.
Although it is redundant with the task manager, tasklist can often show tasks that are hidden otherwise as well as display more information about each of them.
There are several useful parameters such as tasklist -v which displays more information about every task or tasklist -svc which shows related services.
You can also use taskkill to stop running tasks.
Type taskkill -im followed by the executable name or taskkill -pid and the id of the process.
taskkill -im chrome.exe
taskkill -pid 1234
Usually the only way to send input to the command line is with your keyboard. However we can also send input or output using a redirector. A redirector is a special symbol that is used to, as the name suggests redirect the input or output from one command to another.
Lets take a look at a few ways we can use redirectors.
- Command1 && Command2
It only runs the second command if the first runs successfully.
- Command1 & Command2
It runs the second command regardless if the first command returns an error or not.
- Command1 || Command2
Which only runs the second command if the first one fails.
- Command1 | Command2
Which redirects the output of the first command to the second.
You can also combine multiple redirectors. For example:
- Command1 && Command2 || Command3
If the first command runs successfully command2 will be run if not command3 will be run instead.
#9 One Page at a Time
Using a command like tree can yield a huge amount of information displayed on your screen and would require a lot of scrolling and searching to find exactly what you want. Thankfully we can use the more command to view the result of a command, one page or even one line at a time. Simply type your command and redirect its output to the more command.
Tree | More
Press Enter to view one line at a time or space to view one page at a time.
Press control c to cancel.
#10 Watch Star Wars
One of the coolest things you can do with the command line is that you can watch the full star wars episode 4 directly form the command prompt. Yes, your eyes are not deceiving you.
This might be not particularly useful, however it is very cool.
To watch the movie, first you have to enable telnet services in your computer. Simply search for “turn windows features on or off” and check the checkbox next to telnet. After telnet is configured go back to your command line and type:
The movie will start immediately.
You now know a number of tips and tricks you can use on the command line to improve your efficiency and productivity. If you liked this short guide you are probably going to love some of our other windows command prompt content. Check out some more guides at the links below: