Essential Windows Command Line Cheat Sheet

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.

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.

CommandExplanationExample
c:Change the current drive to the C:\ drivec:
d:Change the current drive to the D:\ drived:
CD c:\path\to\my_folderChange directory to a specific folderCD c:\Users\John\Documents
CD ..Navigate to the parent (previous) directoryCD .. (from C:\Users\John\Documents to C:\Users\John)
CD .\new_folderNavigate to a folder inside the current directoryCD .\Pictures (from C:\Users\John to C:\Users\John\Pictures)
CD /D d:\videos\Switch drive and directory at the same timeCD /D d:\videos\
CommandExplanationExample
DIRDisplay files and folders in the current directoryDIR
DIR /A c:\apps\Display all files and folders (including hidden/system) in a specific folderDIR /A c:\apps\
DIR /A:DDisplay only folders (directories)DIR /A:D
DIR /A:-DDisplay only files (not directories)DIR /A:-D
DIR /A:HDisplay hidden files and foldersDIR /A:H
DIR /OSort files and folders alphabeticallyDIR /O
DIR /O:SSort files and folders by file size (smallest to largest)DIR /O:S
DIR /O:-SSort files and folders by file size (largest to smallest)DIR /O:-S
DIR /BDisplay only the names of files and folders (bare format)DIR /B
CommandExplanationExample
SORTSort 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 lineSORT "C:\music\playlist.m3u"
`DIR /BSORT /R > ZtoA.txt`List all file/folder names, sort them in reverse alphabetical order, and save to a file
CommandExplanationExample
MOVEMove a file or files from one location to anotherMOVE c:\f1\text.txt c:\f2
MD new_folder / MAKEDIR new_folderCreate a new folder in the current directoryMD Projects
RD new_folder / RMDIR new_folderRemove (delete) an empty folderRD old_backup
CommandExplanationExample
TREEShow the directory structure graphicallyTREE
TREE "C:\Program Files"Show the folder structure of a specific folderTREE "C:\Program Files"
TREE C:\ /FShow the directory structure of the C:\ drive, including all filenamesTREE C:\ /F
CommandExplanationExample
ATTRIBView or change file/folder attributes (e.g., hidden, read-only)ATTRIB
ATTRIB +H +S +R myItemHide a file/folder and set it as a system and read-only itemATTRIB +H +S +R secret.txt
ATTRIB -H -S -R myItemUnhide a file/folder and remove system and read-only attributesATTRIB -H -S -R secret.txt

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.

CommandExplanationExample
COPY text.txt C:\schoolworkCopy the file text.txt to a specified folder (C:\schoolwork)COPY text.txt C:\schoolwork
DEL text.txt / ERASE text.txtDelete the file text.txtDEL text.txt
REN text.txt script.bat / RENAME text.txt script.batRename a file text.txt to script.batREN text.txt script.bat
CommandExplanationExample
REPLACE .\src\hey.txt .\destOverwrite and replace the hey.txt file from src folder with a new one from dest folderREPLACE .\src\hey.txt .\dest
XCOPYCopy files and directories (including subdirectories) to another folderXCOPY C:\folder1 C:\folder2 /S
XCOPY /S folder1 folder2Copy folders and subfolders from folder1 to folder2XCOPY /S folder1 folder2
ROBOCOPYRobust copying of files and directories; only copy if source and destination differROBOCOPY C:\source D:\destination
CommandExplanationExample
EXPAND gameData.cabDecompress a .CAB (cabinet) file to extract its contentsEXPAND gameData.cab
CommandExplanationExample
FC file1.ext file2.extCompare the contents of two files (file1.ext and file2.ext) and display non-matching linesFC file1.txt file2.txt
COMP file1.ext file2.extCompare the contents of two files (file1.ext and file2.ext) and display non-matching itemsCOMP file1.txt file2.txt
FIND "python" in run.batOutput every line that contains the string "python" in the file run.batFIND "python" in run.bat
FIND /C "python" in run.batCount every line that contains the string "python" in the file run.batFIND /C "python" in run.bat
CommandExplanationExample
PRINT resume.txtPrint the contents of the file resume.txtPRINT resume.txt
TYPE test.txtDisplay the contents of the file test.txtTYPE test.txt
`TYPE playlist.m3uSORT /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
CommandExplanationExample
OPENFILES /QUERYQuery and display the list of open filesOPENFILES /QUERY
OPENFILES /DISCONNECTDisconnect files that are open by network usersOPENFILES /DISCONNECT
CommandExplanationExample
MOREDisplay contents of one or more files, one screen at a timeMORE C:\folder\file.txt
ASSOCDisplay or change the file extension association with a file typeASSOC .txt=txtfile
NOTEPADOpen the Notepad application from cmdNOTEPAD
NOTEPAD filename.extOpen the file filename.ext in NotepadNOTEPAD example.txt

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.

CommandExplanationExample
CHKDSKCheck and repair disk problems (local disks only)CHKDSK
CHKDSK /F A:Fix errors on the A: driveCHKDSK /F A:
CHKDSK /R A:Recover data on the A: driveCHKDSK /R A:
CHKDSK /X A:Dismount the A: drive before checking and repairingCHKDSK /X A:
CommandExplanationExample
CIPHER /E classifiedEncrypt the folder classifiedCIPHER /E classified
CIPHER /D secret_recipe.txtDecrypt the file secret_recipe.txtCIPHER /D secret_recipe.txt
COMPACTDisplay or change the compression of files in NTFS partitionsCOMPACT
CommandExplanationExample
DEFRAGPerform disk defragmentation to optimize disk performanceDEFRAG C:
CONVERTConvert FAT disk volume to NTFSCONVERT D: /FS:NTFS
Disk Partition Management
CommandExplanationExample
DISKPARTDisplay and adjust disk partition propertiesDISKPART
FSUTILPerform advanced file system management tasksFSUTIL
CommandExplanationExample
FORMATFormat a disk or partitionFORMAT D:
LABEL d:xRename disk volume D:\ to X:\LABEL D:X
CommandExplanationExample
SUBST p: c:\taxesAssign the virtual drive P:\ to the local folder c:\taxesSUBST p: c:\taxes
SUBST p: /DRemove the virtual drive path P:\SUBST p: /D
CommandExplanationExample
RECOVER d:\data.datRecover a file data.dat from a defective disk D:\RECOVER D:\data.dat
VOLDisplay the current disk volume label and serial numberVOL
CommandExplanationExample
POWERCFGControl power settings and configure Hibernate/Standby modesPOWERCFG /H on
SFC /SCANNOWScan and update protected system filesSFC /SCANNOW

These commands are used to retrieve system information, configure network settings, troubleshoot network issues, and manage network connections.

CommandExplanationExample
VERDisplay the current operating system versionVER
SYSTEMINFOList detailed system configuration, including OS, memory, and network informationSYSTEMINFO
HOSTNAMEShow the computer’s hostname on the networkHOSTNAME
DRIVERQUERYShow all installed device driversDRIVERQUERY
DATEDisplay or set the system dateDATE
TIMEDisplay or set the system timeTIME
GPRESULTDisplay Resultant Set of Policy (RSoP) information for a remote user and computerGPRESULT /R
GPUPDATEUpdate group policiesGPUPDATE
CommandExplanationExample
IPCONFIGDisplay the current Windows IP network configurationsIPCONFIG
IPCONFIG /releaseRelease your current local IP addressIPCONFIG /release
IPCONFIG /renewRequest a new local IP address from the DHCP serverIPCONFIG /renew
IPCONFIG /flushdnsReset the contents of the DNS client resolver cacheIPCONFIG /flushdns
PING google.comSend ICMP requests to google.com to check host availabilityPING google.com
PATHPINGTrace route and provide network latency and packet loss for each router in the pathPATHPING google.com
NETProvide various network services (e.g., manage shares, network drives, etc.)NET
NET use M: \\gameServ /user:"ReadyPlayerOne" player1Assign disk M:\ the path \\gameServ, logging in as “ReadyPlayerOne” and password “player1”NET use M: \\gameServ /user:"ReadyPlayerOne" player1
TRACERTTrace the route to a remote host and find the IP address of each hopTRACERT google.com
NSLOOKUPFind IP addresses associated with a domain name from a DNS serverNSLOOKUP google.com
ROUTEManipulate network routing tablesROUTE
ROUTE PRINTDisplay network route detailsROUTE PRINT
ARP -AList IP addresses and corresponding physical addresses (Address Resolution Protocol)ARP -A
CommandExplanationExample
NETSHConfigure network interfaces, Windows firewall, routing, and remote accessNETSH
NETSTATDisplay current TCP/IP network connections and protocol statisticsNETSTAT
GETMACShow all MAC addresses of the network adaptersGETMAC

These commands help you manage processes, system tasks, and scheduled jobs, allowing for efficient handling of background operations, process termination, and system shutdowns.

CommandExplanationExample
SCHTASKSCreate or edit a job in Task Scheduler to automate tasks on your system.SCHTASKS /Create /TN "Backup" /TR "C:\backup.bat" /SC DAILY /ST 08:00
SETList environment variables.SET
PATHDisplay or change the list of folders stored in the %PATH% environment variablePATH
CommandExplanationExample
SHUTDOWN /RRestart the computer.SHUTDOWN /R
SHUTDOWN /S /T 60Shut down the computer after a delay of 60 seconds.SHUTDOWN /S /T 60
CommandExplanationExample
TASKLISTList running tasks on your computer, showing task names and process IDs (PIDs).TASKLIST
TASKLIST /SVCShow services related to each task.TASKLIST /SVC
TASKLIST /VDisplay detailed task information, such as memory usage and status.TASKLIST /V
`TASKLISTFIND “1234”`Get the name of the executable associated with the process ID (PID) of 1234.
TASKKILLEnd 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 10736Terminate the process with the specified PID (10736 in this case).TASKKILL /PID 10736
CommandExplanationExample
REGOpen the Registry Editor for managing Windows registry settings.REGEDIT
RUNAS /USER:user2 program1Execute the program program1 as another user (user2).RUNAS /USER:user2 program1
POWERSHELLOpen a Powershell instance for advanced scripting and automation.POWERSHELL

Create automation scripts using batch commands!

CommandWhat It DoesExample
ECHO Hello World!Print to screenECHO Hello World!
PAUSEWait for user to press a keyPAUSE
CHOICELet user choose an optionCHOICE /M "Do you want to continue?"
TIMEOUT 10Wait 10 secondsTIMEOUT 10
CLSClear screenCLS
EXITClose command lineEXIT
START notepad.exeOpen NotepadSTART notepad.exe
TITLE My ScriptChange window titleTITLE Backup Script
HELPList available commandsHELP

Tip: Batch scripts (saved as .bat files) contain multiple Windows commands you can run together!

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.

ConditionalSyntaxExample
IFExecute a command if a condition is true.IF (%a%==5) echo a is 5
IF-ELSEExecute 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 IFUse IF inside another IF to check multiple conditions.IF (%a%==5) IF (%b%==10) echo both are correct
Infinite LoopCreate a loop that runs indefinitely.:marker <br> do_something <br> GOTO marker
While LoopRepeat commands while a condition is true.:marker <br> IF (%a%==5) ( <br> do_something <br> GOTO marker)
  • 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)

Windows Command Prompt has several shortcut keys to enhance your productivity. Here are some of the most useful ones:

KeyEffect
TabAutocomplete commands or file paths.
Ctrl+FOpen a dialog box to find text in the console.
F1Retype the last command, one character at a time.
F3Retype the last command.
F5Retype the last command without scrolling.
F8Recycle through previous commands.
F2Copy the current command leftward of the cursor.
F4Delete the current command rightward of the cursor.
F6Insert an end-of-file character.
F7List previous commands and select one to run.
F9Retype a command by typing its line number in the command history.

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!

LinkedIn
X
Facebook

Related Articles

Leave a Comment

Your email address will not be published. Required fields are marked *

Copyright © 2025 Yakubu Bello - Cyber Security Expert