Windows CMD Commands:
Learn to use the most common basic CMD Commands for Windows 10 and CMD Network Commands with their syntax and examples in this tutorial:
What Is CMD
CMD stands for Command (.CMD). A command is an instruction given to a computer program that tells the program what has to be done. It is an application that is found in most computers with Windows as the Operating System, and it helps in the execution of the commands entered. It is also called Command Prompt or Windows Command Processor.
Why Is Command Prompt Useful
Command prompt has become increasingly popular with people having no background in IT as it helps to automate several tedious, mundane tasks with the help of a few clicks. The interface allows the user to run multiple commands, and the commands can be executed one after the other. This has proved a boon in the world of automation.
Most users find it difficult to learn and cannot use Command prompt as compared to the user-friendly interface that is available on the modern apps, however, Command prompt can still be used in many situations.
How To Open CMD In Windows
Opening Command Prompt in the Windows Operating System is as simple as a few clicks.
Step 1: Go to the Start Menu. This is at the bottom left of the screen. RUN.
Step 2: Type cmd in the search bar and hit Enter. The ones who love shortcuts in Windows can also use Ctrl+R which routes them to RUN, and then they can search for cmd and hit enter. The best thing about these commands in Windows is that they are not case sensitive, which makes it user friendly.
Let us now look at some of the basic and most commonly used CMD commands in the Command Prompt. In the next section, let us see the list of CMD commands with syntax.
Note: It is important to note that these commands are not case sensitive.
Basic CMD Commands
#1) CD- Change Directory
This command allows users to change from one directory to another or move from one folder to another.
Syntax: CD [/D] [drive:][path]
Example: C:>CD Prog
Some of the other parameters of this command are discussed below. This will make this command more useful.
Parameter- cmd device: This parameter gives specific information about the device which will be used for input and output.
Parameter /d: This parameter is used when the user wants to change the current directory and the current drive as well.
#2) Mkdir
This command is used when subdirectories are to be created within the directories.
Syntax: mkdir [<drive>:]<path>
Example: mkdir fantastic ( to create a directory name “ fantastic”)
#3) REN: Rename
Syntax: ren [<drive>:][<path>]<filename1> <filename2>
Example– ren /?
#4) ASSOC: Fix File Associations
This is one of the most basic and
most common commands. It helps to associate (as the name suggests) some file extensions to some programs. For Example- When we click on .doc (extension), the computer is able to decide that it needs to associate it with Microsoft Word. The screenshot below shows an example of how this command works.
Syntax: assoc [.e
xt[=[fileType]]]
Example: – C:\Users\assoc.txt
#5) FC File compare
The second most common command used is FC, also known as File Compare. This is an interesting feature that allows comparing files that have been changed over time.
Syntax: FC /a [/c] [/l] [/lb<n>] [/n] [/off[line]] [/t] [/u] [/w] [/<nnnn>] [<drive1>:][<path1>]<filename1> [<drive2>:][<path2>]<filename2>
FC/b [<drive1:>][<path1>]<filename1> [<drive2:>][<path2>]<filename2>
Example: FC File 1.txt File 2.txt
There are a few other parameters of FC command, explained below-
Parameter- /a: This parameter helps to concise the output when ASCII comparison is done. It shows the first and the last line in the list of differences.
Parameter /c: This parameter ignores the case sensitive aspect of letters.
Parameter /w: This parameter is very useful when files are compared. It eases the process of comparison of files by compressing or removing the white space in the process of comparison. This parameter /w in the FC command disregards the white space, if any, at the beginning and end of the line.
#6) POWERCFG: Power Configuration
This command gives a report of the power settings of the computer. In situations when the power of the computer drains out quickly, this command can help to generate a complete power efficiency. The report is generated within a minute and is extremely useful to detect any warnings which may impact the performance of the system.
Syntax: powercfg /option [arguments] [/?]
Example: powercfg /?
Another parameter of this command is /list, /L. This parameter lists all the power sources.
#7) SHUTDOWN: Turn off Computer
This command is a very resourceful command. By using this command, users can not just shut down computers but also can control the process of the shutdown. This command is popular in situations where shutdown is part of a planned task.
Users can type shutdown/i on the command prompt and choose to either restart or a complete shutdown on the GUI dialogue box that appears. Users have a choice to avoid this GUI dialogue box by typing the shutdown/s command.
Syntax: shutdown [/i | /l | /s | /sg | /r | /g | /a | /p | /h | /e | /o] [/hybrid] [/fw] [/f] [/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]
Example: shutdown/i
#8) SYSTEMINFO: System Information
This command helps to get system-related information like a network card, Windows OS, or details of the processor. The information provided by this command is easy to comprehend.
Syntax: systeminfo [/s <computer> [/u <domain>\<username> [/p <password>]]] [/fo {TABLE | LIST | CSV}] [/nh]
Example: C:\Users\systeminfo
#9) SFC: System File Checker
This command helps to detect any malware or virus threat by running a scan on the core system files. In order to run this command, Administrator rights are needed. On the CMD command prompt icon, use the right-click key and select the option RUN as Administrator.
Users need to type SFC/SCANNOW to run a diagnostic check to ensure all files are safe from malware and in case of any threat of malware, these files are repaired using the backup files.
Syntax: SFC [/scannow] [/verifyonly] [/scanfile=<file>] [/verifyfile=<file>] [/offwindir=<offline windows directory> /offbootdir=<offline boot directory>]
Example: C:\Users\SFC
#10) .NET USE: Map Drives
This command is used for mapping a new drive. Users also have an option to use File Explorer and use Map Network Drive Wizard, if a new driver needs to be mapped, however, this command makes the process quick through one string of commands.
The command syntax is– Net use (drive name)\\OTHER-COMPUTER\SHARE/persistent.yes . This is considering that \\OTHER-COMPUTER\SHARE is a shared folder on the computer and needs to be mapped to a new drive. It is important to use “persistent” here as it ensures that every time the computer is logged onto, the drive is revamped.
Syntax: Net use (drive name)\\OTHER-COMPUTER\SHARE/persistent.yes
Example: Net use /Persistent: Yes
#11) CHKDSK: Check Disk
This command is a step ahead of the SFC command. It allows the scanning of the complete drive as against the scanning of the core system files done by the SFC command. This command needs to be run as an administrator, and the syntax is CHKDSK/f (drive name). In the below screenshot, we can see that the command could not be executed as Administrator rights were missing.
Syntax: chkdsk [<volume>[[<path>]<filename>]] [/f] [/v] [/r] [/x] [/i] [/c] [/l[:<size>]] [/b]
Example: chkdsk C:
Some important parameters for this command are explained below-
Parameter /f: This parameter helps to fix any errors on the disk. In order to use this parameter, the disk must be locked.
Parameter /v: This parameter shows the name of all files in all directories as the process of checking the disk progresses.
#12) SCHTASKS: Schedule Task
This command is another option apart from the inbuilt wizard in Windows when a schedule for tasks has to be created. Tasks can be scheduled by using the Schedule Task wizard or simply by using the command SCHTASKS.
The frequency of the tasks can be minute, hourly, daily, or monthly and can be set by the /MO command. If the command execution is successful, the following response can be seen- SUCCESS: The Scheduled Task “name of the task” has been created.
Syntax:
schtasks change schtasks create schtasks delete schtasks end schtasks query schtasks run
Example- C :\Users\schtasks
This command also has some important parameters which make this command more useful. These have been discussed below-
Parameter /sc: This parameter specifies the schedule a particular task will follow.
Parameter /tn: This parameter describes the name of each task. It is important that every task has a name that is unique and complies with the rules of the file name. The name should not be more than 238 characters.
Parameter /s: This parameter shows details like the name and IP address of a remote computer. The local computer is the default output for this command.
#13) ATTRIB:
Change File Attributes
Windows OS allows users to change the attributes of a file. The first step is to find the file and then find the property that needs to be changed. There is a simple command as well available in Windows which can be used to change the attributes of a file. It is – ATTRIB.
Syntax: Attrib [{+|-}r] [
{+|-}a] [{+|-}s] [{+|-}h] [{+|-}i] [<drive>:][<path>][<filename>] [/s [/d] [/l]]
Example- C:\Users\Attrib /?
Some of the other parameters used for ‘attrib’ command are mentioned below-
Parameter {+|-}r: This parameter sets or clears the read-only file attribute. (+) is used for setting the attribute and (-) for clearing the attribute.
Parameter /s: This parameter uses ‘attrib’ and command-line options to similar files. Similar files can either be in the current directory or in any of the subdirectories.
Apart from the above-mentioned commands, there are a few more popular commands which are commonly used. Some of these commands are listed below-
a) BITSADMIN: This command is useful when uploading or downloading of data is done either within a network or through the Internet. It also helps to keep a check on the file transfer.
Syntax: bitsadmin [/RAWRETURN] [/WRAP | /NOWRAP] command
Some of the important parameters of this command are discussed below:
Parameter /list: This parameter is used to list all the jobs.
Parameter- gettype: This parameter shows the GUID or the display name of the job.
b) COLOR: This command helps to make changes to the background and foreground color of the command prompt window.
Syntax: color [[<b>]<f>]
Example: color /?
We discuss some more parameters of this command below-
Paramater <b>: This parameter is used to change the background color. When this parameter is used in the format ‘color b1’– it changes the background color to blue.
Parameter <f>: This parameter is used to change the background color. When this parameter is used in the format ‘color fc’, it changes the foreground color to red.
c) COMP: This command allows the user to make a comparison between two files and capture differences.
Syntax: comp [<data1>] [<data2>] [/d] [/a] [/l] [/n=<number>] [/c]
d) FIND/FINDSTR: This command allows users to search ASCII files for any strings.
Syntax- findstr [/b] [/e] [/l | /r] [/s] [/i] [/x] [/v] [/n] [/m] [/o] [/p] [/f:<file>] [/c:<string>] [/g:<file>] [/d:<dirlist>] [/a:<colorattribute>] [/off[line]] <strings> [<drive>:][<path>]<filename>[ …]
e) PROMPT: Using this command, the command prompt can be changed to another drive from C:\>.
Syntax: prompt [<text>]
Example- prompt –$g In this example, the command will display an arrow (–> ) type.
f) TITLE: This command is used to make alterations to the title of the command prompt window.
Syntax: title [<string>]
Example: title /?
Parameter <string>: This parameter helps to set the title of the command prompt. It specifies the text which shows as the title of the command prompt.
g) REGEDIT: This command is extremely popular when keys are edited in the Windows registry. This command should be used very carefully.
Syntax:
reg add reg compare reg copy reg delete reg export reg import reg load reg query reg restore reg save reg unload
h) ROBOCOPY: This command is used to copy files or directories from a particular location to a different location. It can also be used to copy an entire drive.
Syntax: robocopy <source> <destination> [<file>[ …]] [<options>]
Now, let us also discuss some CMD commands for Network.
CMD Network Commands
#14) IPCONFIG: IP Configuration
This command is extremely useful when troubleshooting the network is required. When we type IPCONFIG in the command prompt, we get detailed information like IP address, Subnet Mask, Default Gateway IP, and current domain of the network. These details are important in the troubleshooting process of the router or any other connectivity issue.
Syntax: ipconfig [/allcompartments] [/all] [/renew [<adapter>]] [/release [<adapter>]] [/renew6[<adapter>]] [/release6 [<adapter>]] [/flushdns] [/displaydns] [/registerdns] [/showclassid <adapter>] [/setclassid <adapter> [<classID>]]
Example-C:\Users\IPCONFIG
#15) Network Statistics NETSTAT
This command ensures the prevention of any virus attack on the computer. We need to type “NETSTAT” in the command prompt and we get details of all the TCP connections which are currently active.
Syntax: NETSTAT [-a] [-b] [-e] [-n] [-o] [-p <Protocol>] [-r] [-s] [<interval>]
Example: C:\Users\Netstat (shows active connections)
TRACERT is a really interesting command offered by Windows. It is especially meant for users who want to look at the routing of Internet traffic from their own browser to any remote system like a Google server. As the name suggests, it traces the route of the packets which are sent to a remote address which can be a website or even a server.
The information this command provides includes:
· Number of hops (number of intermediate or connecting servers) before the destination was reached.
· Time is taken to reach each of these hops.
· Name of the hops and the IP address of the hops.
This command wonderfully displays the route and hops of any Internet request and how these change when the location to access the web changes. It also helps to detect glitches in a router or a switch on a local network.
Syntax: TRACERT [/d] [/h <maximumhops>] [/j <hostlist>] [/w <timeout>] [/R] [/S <srcaddr>] [/4][/6] <targetname>
Example: C:\Users\ Username>TRACERT google.com
#17) PING: Send Test Packets
This command is extremely useful, especially for IT Professionals. It helps the analyst run checks if the computer is able to access and connect to another computer or another network. It also helps to detect if there are any issues with the connection.
This command also tracks the time for sending packets and this time is calculated in milliseconds, which is quick enough to detect any network glitches. In the below screenshot, the required details can be entered in the format specified to get the information.
Syntax: PING [/t] [/a] [/n <count>] [/l <size>] [/f] [/I <TTL>] [/v <TOS>] [/r <count>] [/s <count>] [{/j <hostlist> | /k <hostlist>}] [/w <timeout>] [/R] [/S <Srcaddr>] [/4] [/6] <targetname>
Example: C:\Users\username\ PING[-t]
Some of the parameters used for this command are mentioned below:
Parameter /t: This parameter is used to send Ping requests to a specific destination until there is an interruption.
Parameter /n<count>: This parameter states the count of echo requests sent. The default count is 4.
#18) PathPing
This command serves the same purpose as that of TRACERT but yields more information. It provides a detailed analysis of the route that a packet sent to a particular destination takes. It also provides information for the loss of packets at each hop it takes.
Syntax: pathping [/n] [/h <maximumhops>] [/g <hostlist>] [/p <Period>] [/q <numqueries> [/w <timeout>] [/i <IPaddress>] [/4 <IPv4>] [/6 <IPv6>][<targetname>]
Example: C:\ Users\pathping www.google.com
#19) GETMAC Media Access Control
Media Access Control is a unique address that is assigned by the manufacturing company to all the devices which meet the standards of IEE 802. This MAC address also helps users to keep control of devices that are allowed to connect to the network. It is possible to see multiple MAC addresses, and this is because there could be multiple network-related adapters on the network.
Syntax: getmac[.exe][/s <computer> [/u <domain\<user> [/p <password>]]][/fo {table | list | csv}][/nh][/v]
Example: C:\Userss\getmac /?
#20) NSLOOKUP- Name Server Lookup
This command helps the users to find the records pertaining to the name server of any domain name.
Syntax: nslookup [exit | finger | help | ls | lserver | root | server | set | view] [options]
Example: C:\Users\Username>nslookup
#21) NETSH- NETWORK SHELL
This command is a network command which is used for gathering details of network adapters available on the system. It helps to check and set up the network adapters.
Syntax: netsh [-a <Aliasfile>][-c <Context>][-r <Remotecomputer>][-u [<domainname>\<username>][-p <Password> | [{<NetshCommand> | -f <scriptfile>}]
Example: C:\Users\netsh dump \?
Parameter /?: This parameter shows the list of commands.
Parameter dump: This parameter displays a configuration script.
#22) ARP
Arp command allows the user to show, delete, and make additions to ARP information of the devices on the network.
Syntax: arp [/a [<inetaddr>] [/n <ifaceaddr>]] [/g [<inetaddr>] [-n <ifaceaddr>]] [/d <inetaddr> [<ifaceaddr>]] [/s <inetaddr> <etheraddr> [<ifaceaddr>]]
Example: C:\Users\arp –a
#23) NBTSTAT
This command helps to show all the current protocol statistics and current TCP/IP connections (NETBIOS over TCP/IP). It uses NBT to resolve issues related to NETBIOS name resolution.
Syntax: nbtstat [/a <remotename>] [/A <IPaddress>] [/c] [/n] [/r] [/R] [/RR] [/s] [/S] [<interval>]
Example: C:\Users\nbtstat
#24) Finger
This command helps to gather information about the user. This can include information related to the last login, last read time for emails, etc.
Syntax: finger [-l] [<user>] [@<host>] […]
Example: finger @ host: This parameter specifies the server on the remote system from which user information is required.
#25) Hostname
This command shows the hostname of the computer.
Syntax: hostname
Example: C:\Users\hostname
#26) Net
This command allows the user to see and find out details of the network settings and update and solve network-related issues.
Syntax: net [accounts | computer | config | continue | file | group | help | helpmsg | localgroup | name | pause | print | send | session | share | start | statistics | stop | time | use | user | view]
Example: C:\Users\net [accounts]
#27) Route
This command is used to check and make changes to the route table of the computer.
Syntax: route [-f] [-p] [-4|-6] command [destination] [MASK netmask] [gateway] [METRIC metric] [IF interface]
Example: C:\Users\route. PRINT
#28) WHOIS
This command is useful when users want to find the domain name or the IP address. It searches the WHOIS database for relevant objects.
Syntax: whois [ -h HOST ] [ -p PORT ] [ -aCFHlLMmrRSVx ] [ -g SOURCE:FIRST-LAST ]
[ -i ATTR ] [ -S SOURCE ] [ -T TYPE ] object
Example: whois [-h]
Note: This command could not be executed due to admin restrictions.
Parameter whois –v: This parameter is used to print the whois information for the domain name.
Usage: whois.exe[-v]domainname [whois.server]
Interestingly, there are some useful tricks of command prompt which helps to enhance the experience of using Windows CMD commands and will prove to be time-saving as well.
Let us share some of the useful tricks below-
CMD Command Tricks
#1) Command History
This trick helps users to recall commands which have been used in the past but they are not able to recall.
Trick: doskey/history
#2) Run multiple commands
This trick is very efficient and time-saving when more than one command needs to be run back to back. All we need to do is to use “&&” between the two commands.
Example: assoc.txt && IPCONFIG
#3) Function keys and their usage
We have discussed an extensive list of commands available in the command prompt. Now, you must be thinking if you need to remember all of them? The answer is No.
We have been talking about the user-friendliness of Command Prompt in Windows and trust me, in case one forgets these commands, it is easy to retrieve the list of commands.
Follow the below-mentioned steps-
Step 1: Open the Command Prompt by clicking on the Start Menu and typing cmd. Alternatively, one can also use a shortcut- Ctrl+R (key), and on the Run dialogue box, type cmd, and press Enter.
Step 2: In order to retrieve the list of commands- Type Help and press Enter. This will help to list down all the commands in alphabetic order, and the commands can be found by scrolling up and down. The list may vary depending upon the version of Windows used.
Below is a list of the function keys which can help to enhance the experience with CMD commands.
#4) Send output to clipboard
This trick is very useful and efficient when the result or output of the command needs to be saved. This trick saves a lot of time by saving the output of the command to the Windows clipboard as against the traditional copy and paste method.
Trick: Assoc.txt| clip
#5) Abort Command
This trick helps to stop the execution of the command if the Enter key has been pressed by mistake.
Trick: CTRL+C