The Command Prompt, also known as CMD or Command Line Interface (CLI), is a powerful tool in the Windows operating system.
While modern graphical user interfaces have become the norm, the command prompt remains an essential tool for advanced users and system administrators.
You can efficiently perform various tasks, automate processes, troubleshoot issues, and unleash the full potential of your Windows machine, thanks to a deep understanding of CMD commands.
This article will introduce some of the most useful CMD commands. These commands cover network administration, device management, and file and data manipulation.
Table Of Content
- The cd Command
- The chkdsk Command
- The choice Command
- The cipher Command
- The color Command
- The comp Command
- The compact Command
- The copy Command
- The date Command
- The defrag Command
- The del and erase Commands
- The driverquery Command
- The fc Command
- The find Command
- The ftype Command
- The getmac Command
- The label Command
- The makecab Command
- The msinfo32 Command
- The nslookuo Command
- The path Command
- The powercfg Command
- The prompt Command
- The route Command
- The schtasks Command
- The tasklist Command
- The tree Command
01. The cd Command
The current directory location can be seen or modified with the cd (change directory) command.
> cd <directory>
When used with a directory parameter, the command outputs the current working directory.
If you wish to switch to another directory, simply add the name of the directory as the parameter. For instance, to change the location to a directory named Users, you can use the following command:
As you can see, the prompt changes to reflect the successful execution of the cd command.
Switch to a Different Disk
The /d flag before the path allows you to move to a destination located on a different disk. For instance, to switch to disk G, use the following version of the cd command:
cd /d G:
You can also use the cd command to go back to the previous directory:
02. The chkdsk Command
The main use of the chkdsk command is to scan the local file system and metadata for any potential errors.
chkdsk <volume> <options>
Note that If you use the chkdsk command without any parameters of flags, it will display the present state of the disk but doesn’t rectify any errors.
You can use additional settings, like the /f option, to fix disk errors.
chkdsk <volume> /f
As you saw, the command makes an effort to correct disk defects. If the disk is in use by another user, the command won’t run because it could potentially disrupt the process of saving data for that user.
If you chose “Y”, the command would run after the next system restart. On the other hand, the system remains unaffected if you enter “N”
03. The choice Command
This is an interesting command where you ask a user to choose from a list of predetermined choices.
Note that, if you don’t provide a list of choices, the system will simply generate two options – Y and N.
You can use the /c flag to use the command to show a list of choices. For instance, the following version displays three choices, “Y”, “N”, and “C”.
choice /c ync
You can add additional information with the /m flag. For instance, in the following example, you can see that we combined the /c and /m flags to offer more information about the choices displayed on the screen:
choice /c ync /m "Yes, No, Continue"
04. The cipher Command
The” command displays and changes a file or directory’s encryption.
> cipher <option> <file or directory>
When used without any parameters, the command displays the encryption status for all files and directories in the current location. As you can guess, U stands for “unencrypted,” whereas ‘E’ stands for “encrypted.”
Next, you can use the /e option can be used to encrypt a file in the current directory:
cipher /e <File Name>
As you can see, the command encrypted the file. This can be further verified by running the command without any parameter.
The E indicates that the file has been encrypted.
05. The color Command
The color command modifies the text and background colors in the terminal.
The color choices are based on hexadecimal values between 0 and f. You can run the help command to get the full list of color choices.
For instance, use the following command to make the background purple (5) and the typeface light green (a).
Run the “color” command without any parameters to go back to the console’s default colors.
06. The comp Command
The comp (short for compare) command is used to compare the contents of two files. When two files vary, the command indicates that the contents are different.
comp <file 1> <file 2> <options>
The comp command also provides an interactive prompt to enter file names and extra options when used without any arguments.
The following screenshot shows the output when the comp command iss used to compare two files – f1.txt and f2.txt.
07. The compact Command
The compact command launches a built-in utility for compressing (and decompressing) files and directories.
compact <options> <file>
When used without any additional parameters, the command reports the current directory’s compression status.
If you wish to compress a file, use the /c flag and the file name:
compact /c User_testfile1.txt
In contrast, you can use the /u argument to uncompress a file.
The compact command is a really simple way of compressing big files and directories to conserve disk space.
08. The copy Command
The copy command is used to copy one or more files from one location to another. The syntax of the command is:
copy <options> <source> <destination>
For example, try the following to duplicate the content of one file into another at the same location:
copy User_testfile1.txt User_testfile1_copy.txt
The command transfers all the contents from the source file into the new one.
09. The date Command
The date command displays and changes the system’s current date.
When used without any parameters, the command prints the current date and asks if you wish to set a new date:
To change the system’s current date, enter the date in the format mm-dd-yyyy, or press CTRL+C to quit.
To print simply the current date without changing the system state, use the /t parameter:
> date /t
10. The defrag Command
Did you know that files are stored as fragments on the disk?
The defrag command consolidates file fragments and “defrags” the disk. As a result, you’ll see a marked improvement in the system’s performance.
defrag <volumes> <options>
You can use the following version of the command to defrag the disk and optimize the disk storage structure.
defrag C:\ /d /g
11. The del and erase Commands
The del and erase commands have similar operations, in that they remove files permanently from the disk. We recommend you should study the technical differences between deleting and erasing data from disk.
del <options> <file(s)>
erase <options> <files(s)>
12. The driverquery Command
Administrators often need to view the details of the installed device drivers and related information.
For this, you can use the driverquery command. This command works for both local and remote systems.
As you can see, when you use driverquery command without any parameters, it displays device driver information for the local computer. You can use additional parameters to format the output or run the command on a remote machine.
13. The fc Command
If you need to compare two or more files, you can use the fc (file compare) command. If there is a discrepancy between the files, the output prints the contents to the console.
fc <options> <file 1> <file 2>
14. The find Command
You may use the “find” command to look for a specified string in a file and get the relevant line of text. When a match is discovered, the result is output.
find <string> <file>
The command searches for an exact match before returning the file name and the text line containing the string. If the command can’t find the text in the file, it simply returns the filename.
15. The ftype Command
This command displays and modifies the file type and extension association..
ftype <file type>=<open command>
As you can see, the command displays the programs associated with each file so that you know which file extension is set to open with which software.
If you wish to find out the current file extension and type association for a specific file type, simply add it as the parameter to the command. For instance, to find the software associated with text files, use the following command:
16. The getmac Command
The getmac command retrieves all network cards’ MAC addresses from the computer or network. The command further displays the protocols related to each address
The command offers several options that let you format the output or get comprehensive information about a remote computer. For instance, use the following command to get the MAC addresses in a CSV file:
getmac /fo csv
17. The label Command
The label command displays, modifies, or deletes a disk’s volume label (also known as the disk name). Note that because of the impact of this command, you need administrator privileges.
The label command launches a prompt to alter the name and, in the absence of any parameters, displays the label for the current drive:
The command prompts you to enter a new name to replace the existing label name (or press Enter to delete the label). Press Y to accept the change, or N to maintain the current name.
18. The makecab Command
As the name suggests, this command creates a cabinet (.cab) file. These Windows-only files are an archive format that supports lossless data compression and archive integrity.
makecab <options> <source> <destination>
19. The msinfo32 Command
The msinfo32 command launches the System Information window that shows essential information about the system.
20. The nslookup Command
The nslookup is a simple tool for diagnosing the issues in DNS infrastructure. The command offers both a non-interactive and an interactive mode.
nslookup <host> <command> <options>
When you launch the command without any parameters, nslookup enters interactive mode. As you can see in the following screenshot, the command shows DNS records for a domain name.
21. The path Command
You can view the contents of the PATH environment variables with this command. This is usually a list of folders pointing to executable files.
Use a semicolon (;) to divide each location into its own PATH entry, like in the example below:
path <location 1>; <location 2>
22. The powercfg Command
This command launches the powercfg.exe program to manage the system’s power plans. The monitoring tool highlights the issues with a device’s battery life and energy efficiency.
powercfg <options> <arguments>
For instance, use the command with the /list parameter to get the details of the active power plan.
> powercfg /list
In the above screenshot, you can see that the star (*) indicates the active power plan.
23. The prompt Command
The prompt command can switch the CMD prompt display with the supplied string. Note that the default prompt is the current directory location followed by the greater-than symbol (>).
prompt <string and variables>
The prompt command provides a number of options for adding unique characters or other functionality to the prompt. For instance, use the following command to transform the prompt into an arrow.
The change to the prompt will persist throughout the command-line session. To restore the default prompt, simply enter the command without any parameters.
24. The route Command
The local routing table entries are shown and modified using the route command.
route <options> <command> <value>
> route print
25. The schtasks command
The schtasks command facilitates scheduling system-wide operations for commands or programs. The duties are carried out frequently or at set intervals.
26. The tasklist Command
The tasklist command displays all active processes and their memory utilization on a local or remote machine. The command is a great option for finding more information about the processes.
Without any parameters, this command outputs a list of all active processes on the local machine.
27. The tree Command
The tree command shows a tree-like representation of the contents of a disk or directory.
> tree <options> <path>
Whether you are a system administrator, a power user, or simply an individual seeking deeper Windows knowledge, mastering the Command Prompt is an indispensable skill for Windows users. It provides unparalleled control, efficiency, and automation capabilities. You can easily navigate directories, manage files, troubleshoot network issues, and perform various administrative tasks.
You can automate repetitive actions by harnessing the power to batch processing and scripting.
Q. What does Windows Command Prompt do?
A. Users can communicate with the operating system via text-based commands using the Command Prompt, sometimes called CMD. It offers an easy way to launch programs and carry out different operations without relying on a graphical user interface.
Q. How do I open the Command Prompt?
A. To open the Command Prompt in Windows, you can follow these steps:
Press the Windows key + R to open the Run dialog box.
Type “cmd” or “cmd.exe” and press Enter.
Alternatively, you can search for “Command Prompt” in the Start menu and click the result.
Q. What are some essential CMD commands every user should know?
A. There are several CMD commands that are very handy for everyday tasks. They include:
1. cd: Change directory.
2. dir: List files and folders in the current directory.
3. mkdir: Create a new directory.
4. copy: Copy files from one location to another.
5. del: Delete files.
6. ipconfig: Display IP configuration information.
7. ping: Send a network request to a specific IP address or domain.
8. tasklist: List all running processes.
9. shutdown: Shut down or restart the computer.
A. If you need assistance with a specific CMD command, you can use the built-in help feature. Simply type the command followed by “/?” and press Enter. This will display detailed information about the command, including its syntax and available options.
Q. Can I customize the appearance of the Command Prompt?
A. Yes, you can customize the appearance of the Command Prompt to suit your preferences. Right-click on the title bar of the Command Prompt window and select “Properties.” You can modify settings such as the font, colors, and window size from there.
Q. Are there any advanced CMD commands for power users?
A. There are advanced CMD commands that offer additional functionality for power users and system
administrators. Some examples include:
diskpart: Manage disks, partitions, and volumes.
sfc: Scan and repair system files.
regedit: Access and modify the Windows Registry.
netstat: Display active network connections and listening ports.
robocopy: Advanced file and directory copying.
powercfg: Configure power settings and check power usage.