10 Windows Command Prompt (CMD) Commands
How to Access the Windows Command Prompt
To open the command prompt in Windows 10 and Windows 11, follow these steps:
- Press Windows + R to open the Run command window.
- Type “cmd” into the box.
- Hit Enter or click OK.
Windows Command Prompt Commands
- Assoc
- Use
assoc
to display or change file type associations. This command lists all the file extensions and their - associated programs.Example:
assoc .txt=
changes the default program for.txt
files.
Most files on Windows are associated with a specific program
that is assigned to open the file by default. At times, remembering
these associations can become confusing. You can remind yourself by entering
the command assoc to display a full list of filename extensions and program associations.
You can also extend the command to change file associations.
For example, assoc .txt= will change the file association for text files to
whatever program you enter after the equal sign. The assoc command itself will reveal
both the extension names and program names, which will help you properly use this command.
- Cipher
- Securely delete files from an NTFS volume by overwriting them with random data.
- Example: cipher /w:C:\ wipes free space on the C: drive without affecting existing files.
Deleting files on a mechanical hard drive doesn’t really delete them at all. Instead, it marks the files as no longer accessible and the space they took up as free. The files remain recoverable until the system overwrites them with new data, which can take some time.
The cipher command, however, lets you wipe a directory on an NTFS-formatted volume
by writing random data to it. To wipe your C drive, for example, you’d use the cipher
/w:d command, which will wipe free space on the drive. The command does not overwrite
undeleted data, so you will not wipe out the files you need by running this command.
- File Compare
- Compare two files to highlight their differences.
- Example: fc file1.txt file2.txt compares two text files. Use /b, /c, and /l for binary, case-insensitive, and ASCII text comparisons, respectively.
You can use this command to identify differences in text between two files. It’s particularly useful for writers and programmers trying to find small changes between two versions of a file.
Simply type fc and then the directory path and file name of the two files you want to compare.
You can also extend the command in several ways. Typing /b compares only binary output, /c
disregards the case of text in the comparison, and /l only compares ASCII text.
- Ipconfig
- Display the current IP address configuration of your computer.
- Examples:
- ipconfig /release releases the current IP address.
- ipconfig /renew requests a new IP address.
- ipconfig /flushdns clears the DNS cache.
This command relays the IP address that your computer is currently using. However, if you’re behind a router (like most computers today), you’ll instead receive the local network address of the router.
Still, ipconfig is useful because of its extensions. ipconfig /release followed by
ipconfig /renew can force your Windows PC into asking for a new IP address, which is useful
if your computer claims one isn’t available. You can also use ipconfig /flushdns to refresh your DNS address. These commands are great if the Windows network troubleshooter chokes,
which does happen on occasion.
- Netstat
- List all active connections and listening ports.
- Example: netstat -an shows all connections and listening ports, along with their state.
Entering the command netstat -an will provide you with a list of currently open ports
and related IP addresses. This command will also tell you what state the port is in;
listening, established, or closed.
This is a great command for when you’re trying to troubleshoot devices connected to your
PC or when you fear a Trojan infected your system and you’re trying to locate a malicious
connection.
- Ping
- Test connectivity between your computer and a network device.
- Example: ping google.com sends packets to Google’s server to check connectivity.
Sometimes, you need to know whether packets are making it to a specific networked device.
That’s where ping comes in handy.
Typing ping followed by an IP address or web domain will send a series of
test packets to the specified address. If they arrive and are returned, you know the device
is capable of communicating with your PC; if it fails, you know that there’s something
blocking communication between the device and your computer. This can help you decide if
the root of the issue is an improper
configuration or a failure of network hardware.
- PathPing
- Combines the functionality of ping and tracert to provide detailed route analysis.
- Example: pathping google.com provides information about the route and packet loss at each router.
This is a more advanced version of ping that’s useful if there are multiple routers between your PC and the device you’re testing. Like ping, you use this command by typing pathping followed by the IP address, but unlike ping, pathping also relays some information about the route the test packets take.
- Tracert
- Trace the path packets take to a network host.
- Example: tracert google.com lists each hop along the way to Google’s server and the time taken.
The tracert command is similar to pathping. Once again, type tracert followed by the IP address or domain you’d like to trace. You’ll receive information about each step in the route between your PC and the target. Unlike pathping, however, tracert also tracks how much time (in milliseconds) each hop between servers or devices takes.
- Powercfg
- Manage and monitor power settings and energy consumption.
- Examples:
- powercfg hibernate on enables hibernation.
- powercfg /a shows available power-saving states.
- powercfg /devicequery s1_supported lists devices that support connected standby.
Powercfg is a very powerful command for managing and tracking how your computer uses energy. You can use the command powercfg hibernate on and powercfg hibernate off to manage hibernation, and you can also use the command powercfg /a to view the power-saving states currently available on your PC.
Another useful command is powercfg /devicequery s1_supported, which displays a list of devices on your computer that support connected standby. When enabled, you can use these devices to bring your computer out of standby, even remotely.
- Shutdown
- Shut down or restart your computer.
Examples: - shutdown /s shuts down the computer.
- shutdown /r restarts the computer.
- shutdown /r /o restarts the computer and opens the Advanced Start Options menu.
Windows 8 introduced the shutdown command that, you guessed it, shuts down your computer.
This is, of course, redundant with the already easily accessed shutdown button, but what’s not redundant is the shutdown /r /o command, which restarts your PC and launches the Advanced Start Options menu, which is where you can access Safe Mode and Windows recovery utilities. This is useful if you want to restart your computer for troubleshooting purposes.