UIs in Windows allows doing a lot of tasks. However, UIs are human-friendly but not really computer-friendly: you can’t launch automatically a task that does “Windows (previously the start menu) > Shutdown button > Restart”. Windows command prompt commands and, in fact, commands, in general, are a mix between a programming language and actions you can do in the user interface.
The purpose is to type a sequence of words that explains computer what you want to do. The added benefits compared to UIs is that you can launch dozens to a hundred (!) of commands you prepared in a text file by a single click. Even better, you can schedule it to launch at a specific time. But it’s still easier than programming. That’s why the command prompt is so popular in the developer’s community. So if you want to benefit, it’s time to get to know useful cmd commands!
What you can do in a command line depends on the program understanding your commands. In Windows, it’s either cmd.exe or PowerShell. PowerShell is nice but it requires .NET framework and you may not have access to it in Windows Recovery or Windows Safe Mode.
On the other side, cmd.exe represents the shell you’re going to use in such cases listed above. As well, .bat files are used by cmd.exe and are still the most common way to distribute shell scripts in Windows: so learning cmd.exe means you can read .bat files yourself.
In order to launch Win 10 command prompt, click on the Windows menu, then go in Windows System folder and open Command Prompt. Please note that if you run the command prompt without administration rights, all cmd commands typed inside it will be without rights as well. That’s nice to avoid problems while learning.
Let’s start by displaying text with echo:
echo Testing currently CMD
This will display the text after the echo. Congratulations on your first command! Displaying things is helpful in scripts and in loops, in order to show a list or to indicate progress.
In order to display two lines:
echo Testing currently CMD & echo Next line
The & operator allows executing two commands in one line. It’s mainly useful in commands you directly type. That’s important especially if something must launch quickly after another task.
In command line you often work with files, so you may want to know what are current files in the folder you’re in. Right, you can use the Windows Explorer too in another window but when you just can’t, the command prompt list directory method is the way to go. Also, you can ignore or show hidden files more easily.
Now, you may be looking for a specific file. You have a starting point but you don’t know the exact folder. In dir you can show all files in current directories, but also files in subdirectories in one command:
But when you know a little more dir, it allows you to do searches. It has a way different behavior than Windows Explorer search but it’s useful. Let’s say you need to find a file with the word SQL in the filename:
dir /S *sql*
Please note that if you search the word put, it will match also the filename input or output as both words contain put. The search is case-insensitive, as Windows generally ignore cases when it’s about files and directories.
Then you may want to display a file’s content using the type command. Don’t do so with too big files though or your command prompt will be filled with too many lines.
That’s the right time to tell you something you should do in all command prompt commands: put double quotes around filenames. Yes, it’s tempting to win few keystrokes and not do it but generally, it will cause you a problem someday. You don’t want to have your filename interpreted as a shell command, and it allows you to more easily use filenames with spaces.
But what to do when that file is just too long to fit on the screen? A single command isn’t enough, that’s why I need to show you how to combine commands.
When a command outputs too much content to fit on the screen, you will need to use the more program. This is one of the simple cmd commands that you will need in many circumstances since the command prompt on Windows 10 can’t contain much text. more works like this: it prints one screen of text and you press the Spacebar to show the next screen of text until you’ve read it all.
However, unlike other commands we’ve seen so far, it takes the text as input. A lot of text. So you need to redirect the text from type command to move, otherwise, it won’t work out. You can do so using the pipe | operator. One the left side of pipe |, you put a command to produce output. On the right side, you write a command that will receive the output and do something with it. So for example when trying to look at a long text file:
type "filename" | more
We use this technique here with type and more, but it can work in other cases. Such as when you look at the Windows command line commands help:
help | more
Note that if you no longer need to show the next screen and you want to leave more, you just need to press the Q letter. You can also press an equal sign = to know the current line number. And even better: you can skip a few lines at the beginning of the output. Example when you want to list a directory but you don’t want to see the header:
dir | more +7
The number of lines you want to skip is written after the plus + operator. By the way, you don’t need to use type to display a file using more. It supports directly file display by putting the filename at the end of the command:
It has an added benefit: more tells your position in the file with a percentage. Generally, if you have the time when a feature is bundled in a command, try to use it instead of chaining commands. You will often find added benefits that may be convenient for you.
But the best pager of the world doesn’t replace a good text editor, so sometimes you really want to have the output of a command in a file instead. Good news: there’s another cmd.exe operator for that, the greater than sign >. You use it like this:
tree /F > "files.txt"
As you can see, first the command is written normally, as you would if you wanted to see the result in that dark Windows 10 window. Then you have the greater than > operator and after this operator, you put the filename where the output will be stored. Much like when you do “File > Save” in an application, you will generally put the name of a new, non-existent file. Well, if you really want, you can put the name of an existing file. Be careful though, this operator will replace the actually existing file, effectively deleting all its contents, much like with “File > Save”.
Even better, there’s a second operator, double greater than >> operator. This one allows appending the output at the end of an existing file. This is really convenient to compare multiple commands output but also you can literally write files with echo commands used in command prompt, much like this:
echo Copying files > "Command log.txt" copy "Big Archive.zip" "Backup Big Archive.zip" echo Copy successful > "Command log.txt"
It’s also a practical way to concatenate two text files. Yes, using the double greater than operator and type program, you can suddenly concatenate two files. Combining good features from different programs is an important aspect in the command line. Type program alone might not look useful, but that’s for this kind of combination that it exists. So for example, concatenating files is useful to combine your monthly reports in CSV:
type "September report.csv" > "Combined report.csv" type "October report.csv" >> "Combined report.csv"
Note that if you give double greater than >> operator the name of a new, non-existing file, it will just create it and put the output, much like what single greater than > operator would have done.
There’s a bonus: all cmd prompt commands support these 2 operators! And since there’s generally never enough bonuses, it would be cool to know some more operators, much like how to safely run multiple related commands.
Now, we’ve seen earlier how to chain two commands with &. The thing is that, when you chain two commands, it’s usually because they’re related and you only want to execute the 2nd command if the 1st worked out.
For example, you want to create a new directory and copy that file in this new directory. Now, if the directory creation failed somehow, are you really sure you want to copy that file? The copy might fail in cascade because the directory doesn’t exist, but the directory creation may have failed because the folder already exists and then your copy may also erase a file you didn’t intend to. That’s exactly where you start to wonder if you really want to run that copy without checking.
By using the double ampersand && operator, the 2nd command will only ever execute if the first one worked correctly. Here’s an example with our create directory then copy:
mkdir "v2" && copy "index.html" "v2"
If you run this command once, assuming you have an index.html file, you will get a new directory and in this directory, there will be a copy of the index.html file. However, if you delete the index.html file in the new v2 directory via Windows Explorer and then you run again the command, you will see that index.html doesn’t get copied: that’s the proof the && operator works out.
But how does it know that? There’s a thing called exit code. When an application exits, it always gives an exit code to the operating system in order to indicate if all gone right or not. This way processes can launch another process and have a simple way to know how the task launched gone. Generally, an exit code of 0 is considered as “Everything went fine!” and if it’s something else than a zero, it’s considered that the application had an error and the number is the error code.
Exit codes are a basic Windows commands concept or even a core concept, hence why it’s integrated straight in the syntax of cmd line commands. Well, exit codes aren’t in a dark number only accessible to Windows command line operators, the exit code of the last command is stored in %ERRORLEVEL% command variable.
In the command line, we often want to extract data and sometimes we need only one line or one special file. It may be simpler for you to tell the computer to find a specific date in your log file instead of scrolling through yourself. That’s the purpose of the find tool. It searches a string in text and shows any line containing that string to allow easy filtering. Let’s get back to the log file filter example, the command would look like this:
find "[07/Oct" "Connections Log.txt"
See how it helps to see more clearly what’s happening? But find does not only works with files! Thanks to the pipe | operator, it can also be used to filter lines you really want to look for, such as your IP address using ipconfig, which is one of the Windows System commands:
ipconfig | find "IPv"
See how it’s convenient? Instead of a whole screen, you get only a few lines with exactly what you want. Maybe you would want to keep it in Windows 10 command prompt list!
Take a look at a few more Windows Prompt commands:
This is one of the most important command prompt windows commands. It is a short form of delete tree. deltree is a command utilized to delete files and directories forever from the computer or laptop. It is an external command that is accessible in the Microsoft operating systems.
This command removes a directory and all the subdirectories and files in it.
To delete more than one files and directories the syntax is as shown below:
DELTREE [/Y] [drive:]path [[drive:]path[…]]
/Y: Crushes assisting to validate if the user wants to delete the subdirectory.
[drive:]path: This defines the name of the directory user wants to remove.
When the user fires the above command in the command prompt windows 10 then it deletes the MyFile directory and everything present in that directory.
This is one of the most important windows commands. Wrong device drivers can point to any quantity of system dilemmas. If users want to view which drivers are placed on a Windows operating system, they can achieve this by executing the driverquery windows command line tool. This command comes under basic cmd prompt commands which gives data about each driver that is being utilized.
The command is:
If a user wants a bit extra report, you can affix the -v switch. Another alternative is to affix the -si switch, which makes the tool to demonstrate signature data for the drivers. Here’s how they seem:
Ping is presumably the easiest of all distinguishing command prompt windows 10 commands. It is utilized to check fundamental TCP/IP connectivity to a web host. To apply it, just enter the command, accompanied by the alias or IP address of the host you need to examine.
Always remember that this command will operate only if the Internet Control Message Protocol (ICMP) movement is permitted to move between the two computers. If at any time a firewall is preventing ICMP traffic, the ping will break.
Ping does an excellent duty of informing users whether two computers can interact with each other over TCP/IP, but if ping does break then users will not give any data regarding the characteristics of the collapse. This is where the windows command prompt commands like pathping are handy. The command is given below:
Pathping is intended for circumstances in which one or more routers live between hosts. It conveys a sequence of packets to each router that’s in the route to the target host in an attempt to discover whether the router is operating moderately or filtering packets. At its purest, the syntax for pathping is same as that of the ping command.
This is one of the best windows command prompt commands. The tasklist command is created to give data about the tasks that are operating on a Windows operating system. Users can put the following command:
The tasklist command has many arbitrary switches. The -m switch, which makes tasklist to illustrate all the DLL modules connected with a job. The next is the -svc switch, which places the settings that back each job. Here’s how they work:
This is one of the basic cmd commands. The taskkill command eliminates a task, either by title or by process ID. The arrangement for this command is manageable. Users must fire the taskkill command with -pid (process ID) or -im (image name) and the title or process ID of the job that they need to stop. Here are two samples of how this command operates:
taskkill -pid 3125
taskkill -im chrome.exe
One can say that this command comes under the most important windows commands. Wicked apps will regularly strive to substitute kernel system files with altered variants in an attempt to gain control of the system. The System File Checker can be utilized to check the probity of the Windows system registers. If any of the folders are discovered to be lost or nefarious, they will be repaired. Users can execute the System File Checker by utilizing this command:
The sfc /scannow command examines all secured system files, and substitute damaged files with a cached model that is placed in a compressed enclosure at %WinDir%\System32\dllcache.
This is one of the most amazing windows command line commands. If a drive that is secured is facing some problems then users can seldom retrieve the data utilizing a service named repair-bde. To apply this command, users require a target drive to which the retrieved data can be recorded, as well as the BitLocker retrieval key or restoration password. The primary syntax for this command is:
repair-bde <root> <target> -rk | rp <root>
Users should define the root drive, the target drive, and both the rk (recovery key) or the rp (recovery password) switch, along with the route to the restoration key or the restoration password. Following is the example:
repair-bde c: d: -rk e:\restore.bek
Conceivably the most valuable of the cmd prompt commands that are developed into Windows is NetDiag. The NetDiag command is outlined to operate a series of analyses on the computer in order to assist the professional sketch out why the computer is encountering networking difficulties. The command is shown below:
Listing the NetDiag command by itself will make all of the possible analyses to be covered. Netdiag can assist users to interpret any amount of network problems such as Monitoring Virtual Private Networks.
The tracert command tracks the path it exercises for a packet to touch a target and displays users an erudition about each jaunt along that path. For example, if users run tracert abc.com, they’ll notice information about each link the packet communicates with on its route to touch the server. If users are having concerns comparing to a website, tracert can explicate where the enigma is transpiring.
The above command is one of the most crucial command prompt windows 10 commands.
You can check this video to get a better idea of Windows prompt commands:
You should now have more tools to use the Windows cmd commands effectively. With all these tips and commands list, you should be able to do new commands but also leverage more from commands you already use, if you used the command line previously.
Now it’s time to practice. Try these commands in a folder you create specifically for tests, copy few files and see what you can do.
About the Author
ByteScout Team of Writers
ByteScout has a team of professional writers specialized in different technical topics. We select the best writers to cover interesting and trending topics for our readers. We love developers and we hope our articles help you learn about programming and programmers.