The Windows Command Prompt (CMD) is a great tool for programmers and regular Windows users because it offers a ton of commands to control the entire Windows operating system. All those commands can boost your productivity as you don’t have to click through all the graphical user interfaces. Therefore, knowing some of the basic Command Prompt commands is never bad.
If you’re interested, keep on reading!
Most of the commands I am going to mention are also compatible with the Windows PowerShell unless there’s an asterisk (*) in front of the command. (e.g. *color)
Here’s an overview of the commands:
To get further information and a list of available parameters of these commands, you can always type
help <command> or <command> /? inside your CMD window.
The first command prompt command of this list is an absolutely basic one. However, you definitely need to know about it!
The cd command is used for changing the directory you are currently working in.
Usually, if you open cmd, the standard working directory is C:\Users\username\.
To navigate to a different directory, you simply need to type: cd [Path]
To navigate to a folder that exists in the current directory, you can just type the name of the folder, not the entire path. (e.g. cd Desktop)
To navigate to the previous folder use cd ..
#2: mkdir & rmdir
We use mkdir to create a folder and rmdir to remove one.
The desired command is followed by the path the folder should be in or by just the name of the folder.
- mkdir Folder1
- rmdir Folder1
- mkdir C:\Users\user1\Folder2
- rmdir C:\Users\user1\Folder2
#3: echo foo > bar.txt
This command is useful for creating a new file with some text in it. If you try to write something in a file that already exists, it’ll get overridden.
This is how you use the command:
echo This is some text > filename.txt
If you want to create an empty file, you can use echo. > filename.txt
Keep in mind that this syntax doesn’t work for PowerShell.
The dir command shows all files and folders of a directory as well as some additional information. You can either specify a path after the command to show the content of a directory you are not currently working in or only type the command to show the contents of the current directory.
The robocopy command copies one or multiple files of a specified path to another path.
The syntax for this command looks like this:
robocopy <source path> <destination path> [file(type)]
If you don’t specify a file or file type, robocopy will copy the whole content from the source path.
To copy multiple files or specific file types you can use an asterisk (*). It basically means “everything”.
For example: robocopy C:\Users\user1 C:\Users\user2 *.txt
There are a ton of additional options for this command. You can have a look at all of them here.
Of course, there also is a command for moving files. The syntax for this command is similar to robocopy and very simple:
move <source file path> <destination path>
move C:\Users\user1\file1.txt C:\Users\user2\
If you don’t specify a filename for the destination, it uses the original filename. Otherwise, the file you want to copy will be renamed to the name you specified in the destination path.
To delete a file using cmd, you just need the del command. It is used like this:
del <file path>
You can either specify a whole path to the file or just type the name of the file if it is inside the current working directory.
Be careful not to confuse this command with rmdir, as rmdir deletes entire folders, not files!
The clip command/attribute copies the output of any desired command. Compared to other commands from this list, the clip command isn’t really a command. In reality, it is an additional instruction that comes after a different command.
So, to copy a command’s output, simply put | clip after it.
echo this is a test | clip
This command copies “this is a test” to the clipboard, as it is the output of the echo command.
The cls command is a pretty simple one. Its only task is to clear the console (CMD/PowerShell) window.
This command doesn’t take any additional arguments.
Echo is used to display text inside the console window (CMD/PowerShell).
It’s rather simple. Just write the text you want to print out after the echo command.
Besides printing out text, the echo command is also used for other features like creating files, etc.
However, printing text to the console is one of its main use cases.
A very useful one this the prompt command. It changes the prompt text in cmd.
The standard prompt is just the current path. (e.g. C:\Users>)
The syntax for the prompt command looks like this:
prompt <new prompt text>
You can either select a basic text as your prompt or use different parameters to display symbols and information.
You can find information about the different parameters and symbols in the official documentation of Microsoft or by typing help prompt inside CMD.
With the color command, you can change the background color and text color of your console window.
For example, the command color a makes the text of your console green.
Here is a list of every available color:
You are allowed to give two parameters to the command.
The first one is the background color, and the second one is the text color.
If you use only one parameter, only the text color will change, and the background color resets to black.
The help command provides you with useful information about the most commonly used commands.
To use it, just type help into CMD or PowerShell.
If you want to get help to a specific command, you can simply write the commands keyword behind the help keyword.
The shutdown command can be used to shut down, restart, and hibernate the computer or to log off a user.
There are a lot of additional parameters to this command. Additionally, you can specify a reason for the shutdown. To get a detailed description of all the parameters, enter shutdown without any parameters.
Nevertheless, here’s a list of the most important parameters.
To shut down immediately, use:
To shut down with a warning and delay, use:
To restart, use:
To abort the shutdown, use:
To log the current user off, use:
Tasklist lists all tasks that are currently running as well as some information about them.
Again, there are multiple arguments you can pass to this command. As always, you can display all possible parameters with help tasklist.
If you do not specify any parameters, the command will list all processes with their corresponding PID numbers, session names, and their memory usage.
With taskkill, you can terminate processes by their PID name or process name.
This command requires some parameters:
- To kill a task by its PID: taskkill /PID <PID>
- To kill a task by its process name: taskkill /IM <name>
Additionally, you can choose to terminate every child process a process started with the /T option.
Systeminfo displays a ton of information about your computer.
For example, the hostname, the OS name & version, the system type, etc.
I suggest trying this command on your own to see what information it shows.
The ipconfig command displays information about the network configuration of your network adapters.
For example, it shows your IP address, your MAC address, and your default gateway.
If you want even more detailed information, you can use ipconfig /all.
Netstat shows you every active connection of your computer.
If you don’t pass any arguments to the command, it will show the protocol, the local address, the foreign address, and the connection state of each connection.
Thanks for reading!