The Windows Command Line (also known as Command Prompt or cmd) is the command-line interface (CLI) built into Microsoft Windows. Think of it like the Windows equivalent of the Terminal on Mac/Linux.
It emulates many commands from the old MS-DOS but is not MS-DOS itself.
Today we’re diving into the Windows Command Line (cmd.exe) — your powerful tool for managing files, troubleshooting systems, and scripting tasks quickly. Whether you’re new to it or just need a handy reference, this cheat sheet will help you move faster and smarter.
Directory Navigation Commands
These commands allow you to navigate between drives, move around folders, list directory contents, and manage file/folder attributes in Windows Command Line (cmd). Below, we break down each command with an explanation and example for easy reference.
Change Drive & Navigate Folders
Command
Explanation
Example
c:
Change the current drive to the C:\ drive
c:
d:
Change the current drive to the D:\ drive
d:
CD c:\path\to\my_folder
Change directory to a specific folder
CD c:\Users\John\Documents
CD ..
Navigate to the parent (previous) directory
CD .. (from C:\Users\John\Documents to C:\Users\John)
CD .\new_folder
Navigate to a folder inside the current directory
CD .\Pictures (from C:\Users\John to C:\Users\John\Pictures)
CD /D d:\videos\
Switch drive and directory at the same time
CD /D d:\videos\
List Directory Contents
Command
Explanation
Example
DIR
Display files and folders in the current directory
DIR
DIR /A c:\apps\
Display all files and folders (including hidden/system) in a specific folder
DIR /A c:\apps\
DIR /A:D
Display only folders (directories)
DIR /A:D
DIR /A:-D
Display only files (not directories)
DIR /A:-D
DIR /A:H
Display hidden files and folders
DIR /A:H
DIR /O
Sort files and folders alphabetically
DIR /O
DIR /O:S
Sort files and folders by file size (smallest to largest)
DIR /O:S
DIR /O:-S
Sort files and folders by file size (largest to smallest)
DIR /O:-S
DIR /B
Display only the names of files and folders (bare format)
DIR /B
Sorting & Saving Directory Listings
Command
Explanation
Example
SORT
Sort lines of text (input via file or command)
SORT < C:\files\list.txt
SORT "C:\music\playlist.m3u"
Sort the contents of a file line by line
SORT "C:\music\playlist.m3u"
`DIR /B
SORT /R > ZtoA.txt`
List all file/folder names, sort them in reverse alphabetical order, and save to a file
Move, Create & Delete Files/Folders
Command
Explanation
Example
MOVE
Move a file or files from one location to another
MOVE c:\f1\text.txt c:\f2
MD new_folder / MAKEDIR new_folder
Create a new folder in the current directory
MD Projects
RD new_folder / RMDIR new_folder
Remove (delete) an empty folder
RD old_backup
View Folder Structures
Command
Explanation
Example
TREE
Show the directory structure graphically
TREE
TREE "C:\Program Files"
Show the folder structure of a specific folder
TREE "C:\Program Files"
TREE C:\ /F
Show the directory structure of the C:\ drive, including all filenames
TREE C:\ /F
Manage File/Folder Attributes
Command
Explanation
Example
ATTRIB
View or change file/folder attributes (e.g., hidden, read-only)
ATTRIB
ATTRIB +H +S +R myItem
Hide a file/folder and set it as a system and read-only item
ATTRIB +H +S +R secret.txt
ATTRIB -H -S -R myItem
Unhide a file/folder and remove system and read-only attributes
ATTRIB -H -S -R secret.txt
File Management Commands
These commands help with managing files in your Windows Command Line, whether you’re copying, deleting, renaming, comparing, or opening files. Use these commands to work efficiently with files and directories.
Copy, Move, and Delete Files
Command
Explanation
Example
COPY text.txt C:\schoolwork
Copy the file text.txt to a specified folder (C:\schoolwork)
Overwrite and replace the hey.txt file from src folder with a new one from dest folder
REPLACE .\src\hey.txt .\dest
XCOPY
Copy files and directories (including subdirectories) to another folder
XCOPY C:\folder1 C:\folder2 /S
XCOPY /S folder1 folder2
Copy folders and subfolders from folder1 to folder2
XCOPY /S folder1 folder2
ROBOCOPY
Robust copying of files and directories; only copy if source and destination differ
ROBOCOPY C:\source D:\destination
File Compression and Decompression
Command
Explanation
Example
EXPAND gameData.cab
Decompress a .CAB (cabinet) file to extract its contents
EXPAND gameData.cab
File Comparison and Finding Differences
Command
Explanation
Example
FC file1.ext file2.ext
Compare the contents of two files (file1.ext and file2.ext) and display non-matching lines
FC file1.txt file2.txt
COMP file1.ext file2.ext
Compare the contents of two files (file1.ext and file2.ext) and display non-matching items
COMP file1.txt file2.txt
FIND "python" in run.bat
Output every line that contains the string "python" in the file run.bat
FIND "python" in run.bat
FIND /C "python" in run.bat
Count every line that contains the string "python" in the file run.bat
FIND /C "python" in run.bat
Viewing and Printing File Contents
Command
Explanation
Example
PRINT resume.txt
Print the contents of the file resume.txt
PRINT resume.txt
TYPE test.txt
Display the contents of the file test.txt
TYPE test.txt
`TYPE playlist.m3u
SORT /unique /o C:\work\unique_play.m3u`
Sort the file playlist.m3u and output only the unique values to a new file unique_play.m3u
Working with Open Files
Command
Explanation
Example
OPENFILES /QUERY
Query and display the list of open files
OPENFILES /QUERY
OPENFILES /DISCONNECT
Disconnect files that are open by network users
OPENFILES /DISCONNECT
File Viewing Utilities
Command
Explanation
Example
MORE
Display contents of one or more files, one screen at a time
MORE C:\folder\file.txt
ASSOC
Display or change the file extension association with a file type
ASSOC .txt=txtfile
NOTEPAD
Open the Notepad application from cmd
NOTEPAD
NOTEPAD filename.ext
Open the file filename.ext in Notepad
NOTEPAD example.txt
Disk Management Commands
These commands allow you to manage disks, file systems, and partitions on your Windows system. They cover tasks like checking and repairing disks, managing partitions, defragmenting, and handling encryption.
Disk Checking and Repair
Command
Explanation
Example
CHKDSK
Check and repair disk problems (local disks only)
CHKDSK
CHKDSK /F A:
Fix errors on the A: drive
CHKDSK /F A:
CHKDSK /R A:
Recover data on the A: drive
CHKDSK /R A:
CHKDSK /X A:
Dismount the A: drive before checking and repairing
CHKDSK /X A:
File Encryption and Compression
Command
Explanation
Example
CIPHER /E classified
Encrypt the folder classified
CIPHER /E classified
CIPHER /D secret_recipe.txt
Decrypt the file secret_recipe.txt
CIPHER /D secret_recipe.txt
COMPACT
Display or change the compression of files in NTFS partitions
COMPACT
Disk Defragmentation and Conversion
Command
Explanation
Example
DEFRAG
Perform disk defragmentation to optimize disk performance
DEFRAG C:
CONVERT
Convert FAT disk volume to NTFS
CONVERT D: /FS:NTFS
Disk Partition Management
Command
Explanation
Example
DISKPART
Display and adjust disk partition properties
DISKPART
FSUTIL
Perform advanced file system management tasks
FSUTIL
Formatting and Labeling
Command
Explanation
Example
FORMAT
Format a disk or partition
FORMAT D:
LABEL d:x
Rename disk volume D:\ to X:\
LABEL D:X
Virtual Drives and Mounting
Command
Explanation
Example
SUBST p: c:\taxes
Assign the virtual drive P:\ to the local folder c:\taxes
SUBST p: c:\taxes
SUBST p: /D
Remove the virtual drive path P:\
SUBST p: /D
Disk Recovery and Volume Information
Command
Explanation
Example
RECOVER d:\data.dat
Recover a file data.dat from a defective disk D:\
RECOVER D:\data.dat
VOL
Display the current disk volume label and serial number
VOL
Power Settings and System File Check
Command
Explanation
Example
POWERCFG
Control power settings and configure Hibernate/Standby modes
POWERCFG /H on
SFC /SCANNOW
Scan and update protected system files
SFC /SCANNOW
System Information and Networking Commands
These commands are used to retrieve system information, configure network settings, troubleshoot network issues, and manage network connections.
System Information Commands
Command
Explanation
Example
VER
Display the current operating system version
VER
SYSTEMINFO
List detailed system configuration, including OS, memory, and network information
SYSTEMINFO
HOSTNAME
Show the computer’s hostname on the network
HOSTNAME
DRIVERQUERY
Show all installed device drivers
DRIVERQUERY
DATE
Display or set the system date
DATE
TIME
Display or set the system time
TIME
GPRESULT
Display Resultant Set of Policy (RSoP) information for a remote user and computer
GPRESULT /R
GPUPDATE
Update group policies
GPUPDATE
Networking Commands
Command
Explanation
Example
IPCONFIG
Display the current Windows IP network configurations
IPCONFIG
IPCONFIG /release
Release your current local IP address
IPCONFIG /release
IPCONFIG /renew
Request a new local IP address from the DHCP server
IPCONFIG /renew
IPCONFIG /flushdns
Reset the contents of the DNS client resolver cache
IPCONFIG /flushdns
PING google.com
Send ICMP requests to google.com to check host availability
PING google.com
PATHPING
Trace route and provide network latency and packet loss for each router in the path
PATHPING google.com
NET
Provide various network services (e.g., manage shares, network drives, etc.)
NET
NET use M: \\gameServ /user:"ReadyPlayerOne" player1
Assign disk M:\ the path \\gameServ, logging in as “ReadyPlayerOne” and password “player1”
NET use M: \\gameServ /user:"ReadyPlayerOne" player1
TRACERT
Trace the route to a remote host and find the IP address of each hop
TRACERT google.com
NSLOOKUP
Find IP addresses associated with a domain name from a DNS server
NSLOOKUP google.com
ROUTE
Manipulate network routing tables
ROUTE
ROUTE PRINT
Display network route details
ROUTE PRINT
ARP -A
List IP addresses and corresponding physical addresses (Address Resolution Protocol)
ARP -A
Advanced Networking Tools
Command
Explanation
Example
NETSH
Configure network interfaces, Windows firewall, routing, and remote access
NETSH
NETSTAT
Display current TCP/IP network connections and protocol statistics
NETSTAT
GETMAC
Show all MAC addresses of the network adapters
GETMAC
Process Management Commands
These commands help you manage processes, system tasks, and scheduled jobs, allowing for efficient handling of background operations, process termination, and system shutdowns.
Task Scheduling and Management
Command
Explanation
Example
SCHTASKS
Create or edit a job in Task Scheduler to automate tasks on your system.
Display or change the list of folders stored in the %PATH% environment variable
PATH
System Shutdown and Restart
Command
Explanation
Example
SHUTDOWN /R
Restart the computer.
SHUTDOWN /R
SHUTDOWN /S /T 60
Shut down the computer after a delay of 60 seconds.
SHUTDOWN /S /T 60
Task Management
Command
Explanation
Example
TASKLIST
List running tasks on your computer, showing task names and process IDs (PIDs).
TASKLIST
TASKLIST /SVC
Show services related to each task.
TASKLIST /SVC
TASKLIST /V
Display detailed task information, such as memory usage and status.
TASKLIST /V
`TASKLIST
FIND “1234”`
Get the name of the executable associated with the process ID (PID) of 1234.
TASKKILL
End one or more tasks running on the system.
TASKKILL /IM "msedge.exe"
TASKKILL /IM "msedge.exe"
Terminate all instances of Microsoft Edge.
TASKKILL /IM "msedge.exe"
TASKKILL /PID 10736
Terminate the process with the specified PID (10736 in this case).
TASKKILL /PID 10736
System Tools
Command
Explanation
Example
REG
Open the Registry Editor for managing Windows registry settings.
REGEDIT
RUNAS /USER:user2 program1
Execute the program program1 as another user (user2).
RUNAS /USER:user2 program1
POWERSHELL
Open a Powershell instance for advanced scripting and automation.
POWERSHELL
Batch Scripting Commands
Batch Scripting Basics
Create automation scripts using batch commands!
Command
What It Does
Example
ECHO Hello World!
Print to screen
ECHO Hello World!
PAUSE
Wait for user to press a key
PAUSE
CHOICE
Let user choose an option
CHOICE /M "Do you want to continue?"
TIMEOUT 10
Wait 10 seconds
TIMEOUT 10
CLS
Clear screen
CLS
EXIT
Close command line
EXIT
START notepad.exe
Open Notepad
START notepad.exe
TITLE My Script
Change window title
TITLE Backup Script
HELP
List available commands
HELP
Tip: Batch scripts (saved as .bat files) contain multiple Windows commands you can run together!
Flow Control
Flow control in batch scripting allows you to direct the execution of a script based on certain conditions. It enables decision-making and iteration for more complex tasks.
Conditional Statements
Conditional
Syntax
Example
IF
Execute a command if a condition is true.
IF (%a%==5) echo a is 5
IF-ELSE
Execute one command if the condition is true, otherwise execute another command.
IF (%a%==5) echo a is 5 ELSE echo a is not 5
Nested IF
Use IF inside another IF to check multiple conditions.
IF (%a%==5) IF (%b%==10) echo both are correct
Infinite Loop
Create a loop that runs indefinitely.
:marker <br> do_something <br> GOTO marker
While Loop
Repeat commands while a condition is true.
:marker <br> IF (%a%==5) ( <br> do_something <br> GOTO marker)
Flow Control Explanation
IF: Checks a condition and runs a command if the condition is true. Example: IF (%a%==5) echo a is 5
IF-ELSE: Adds an else branch to the flow, so a command is run if the condition is false. Example: IF (%a%==5) echo a is 5 ELSE echo a is not 5
Nested IF: You can have an IF inside another IF, which is useful for checking multiple conditions. Example: IF (%a%==5) IF (%b%==10) echo both are correct
Infinite Loop: This creates an endless loop. It is often used with a condition to break out of it. Example: :marker <br> do_something <br> GOTO marker
While Loop: The loop runs repeatedly while a condition is true. Example: :marker <br> IF (%a%==5) ( <br> do_something <br> GOTO marker)
Shortcut Keys
Windows Command Prompt has several shortcut keys to enhance your productivity. Here are some of the most useful ones:
Key
Effect
Tab
Autocomplete commands or file paths.
Ctrl+F
Open a dialog box to find text in the console.
F1
Retype the last command, one character at a time.
F3
Retype the last command.
F5
Retype the last command without scrolling.
F8
Recycle through previous commands.
F2
Copy the current command leftward of the cursor.
F4
Delete the current command rightward of the cursor.
F6
Insert an end-of-file character.
F7
List previous commands and select one to run.
F9
Retype a command by typing its line number in the command history.
Conclusion
With this Windows Command Line Cheat Sheet, you’ll be able to navigate, manage files, control networks, and automate tasks like a pro! Whether you’re troubleshooting a PC, writing a batch script, or just trying to look cool with black screens and white text — cmd has your back.
If you ever feel lost, just remember: COMMAND /? is your best friend!