Top Windows Command Line Cheat Sheet (2024)

Windows Command Line Cheat Sheet

When working on the Windows command line, do you remember how often you kept looking for the same commands? Do you easily mistype in the Windows command prompt as if you were using bash commands, such as “rm” instead of “del”? If you’ve ever been in the situations above, this Windows command line cheat sheet is for you.

The Windows command line is only as powerful as the commands at your disposal, which we’ll expand on in this Windows command prompt cheat sheet. It covers every command you need for important tasks and batch scripting, plus a few delightful surprises if you make it to the end.

Keep a copy of this Windows command line cheat sheet on your desk, in your pocket, or wherever you go. When you’re ready, let’s dive in.

Windows Command Line Cheat Sheet Search

Search our Windows command line cheat sheet to find the right cheat for the term you're looking for. Simply enter the term in the search bar and you'll receive the matching cheats available.

What Is the Windows Command Line?

The Windows command line (Windows command prompt) is the command-line interface (CLI) on Microsoft Windows machines, analogous to the Terminal in Unix/Linux. It emulates many command-line abilities in Microsoft’s deprecated text-only operating system MS-DOS (but it’s not MS-DOS).

Methods to open the Windows CLI:

  • On Windows 10 or above, click Start on the bottom left corner, type cmd, and select Command Prompt.
  • On Windows 8.x or earlier, press Ctrl+R to open the Run dialog box, type cmd into it, and press Enter.

Hence, another name for Windows CLI is “cmd.”

Scripts containing Windows commands (batch scripts) have “.bat” as the file extension. All cmd commands are case-insensitive, so arp and ARP are the same. If you need help using any command, add /? to it, e.g., ARP /? will show the manual for ARP:

Directory Navigation

These commands help you view directories and move directories around.

CommandExplanation
c:Change the current drive to the C:\ drive
d:Change the current drive to the D:\ drive
CD c:\path\to\my_folderChange directory to c:\path\to\my_folder
CD ..Navigate to the parent directory of the current working directory
CD .\new_folderNavigate to the folder new_folder located in the current working directory
CD /D d:\videos\Change the current drive to D:\ and access the folder videos on it.
DIRDisplay files and folders in the current directory
DIR /A c:\apps\Display files and folders in the directory c:\apps\
DIR /A:DDisplay only folders (D: directories)
DIR /A:-DDisplay only files (D: directories; -: not)
DIR /A:HDisplay hidden files and folders
DIR /ODisplay files and folders sorted alphabetically
DIR /O:SDisplay files and folders sorted by file size from smallest to largest
DIR /O:-SDisplay files and folders sorted by file size from largest to smallest
DIR /BDisplay only the names of files and folders in the current working directory
SORTTake input from a source file/pipeline, sort its contents alphabetically (default: A to Z; in reverse: Z to A), and display the output
SORT "C:\music\playlist.m3u"Sort the contents of C:\music\playlist.m3u line by line
DIR /B | SORT /R /O ZtoA.txtList all file and folder names in the current working directory, sort them in reverse alphabetical order, and save the sorted output to a file ZtoA.txt:
MOVEMove a file or files
MOVE c:\f1\text.txt c:\f2Move a file text.txt from one folder c:\f1 to another folder c:\f2
MD new_folderMAKEDIR new_folderCreate a new folder called new_folder in the current directory
RD new_folderRMDIR new_folderDelete the folder called new_folder in the current directory
TREEShow the directory structure of a disk/folder
TREE "C:\Program Files"Show the directory structure of the folder “Program Files” on the disk C:\
TREE C:\ /FDisplay the names of the files in each folder in the directory structure of the C:\ drive
ATTRIBDisplay/set the attributes of the files in the current directory
ATTRIB +H +S +R myItemHide a file/folder myItem
ATTRIB -H -S -R myItemUnhide a file/folder myItem
TREE demonstration

File Management

The following commands are for managing and manipulating files.

Like Unix, cmd supports pipelines: you may pass the output of a command to the next one by sandwiching the pipe character “|” between both.

CommandExplanation
COPY text.txt C:\schoolworkCopy the file text.txt to a folder with the path C:\schoolwork
DEL text.txtERASE text.txtDelete the file text.txt
REN text.txt script.batRENAME text.txt script.batRename a file text.txt to script.bat
REPLACE .\src\hey.txt .\destOverwrite; replace a file named hey.txt in a local folder src with another hey.txt in a local folder dest, both files sharing the same name.
Warning: Don’t specify .\dest\hey.txt anywhere here.
XCOPYCopy files and directory trees to another folder.
XCOPY is similar to COPY but with additional switches to specify the source and destination paths in detail.
XCOPY /S folder1 folder2Copy folders and subfolders of folder1 to folder2
ROBOCOPYRobust copying of files and directories: by default, such copying only occurs if the source and destination differ in time stamps or file sizes.
EXPAND gameData.cabDecompresses the compressed .CAB cabinet file gameData.cab
FC file1.ext file2.extCompare the contents of two files (file1.ext, file2.ext) and display non-matching lines
COMP file1.ext file2.extCompare the contents of two files (file1.ext, file2.ext) and display non-matching items
FIND "python" in run.batOutput every line that contains a text string (which you must enclose in quotation marks) "python" in the file run.bat
FIND /C "python" in run.batCount every line that contains a text string (which you must enclose in quotation marks) "python" in the file run.bat
PRINT resume.txtPrint contents of a file resume.txt
OPENFILES /QUERYQuery/display open files
OPENFILES /DISCONNECTDisconnect files opened by network users.
TYPE test.txtDisplays the contents of the file test.txt
TYPE playlist.m3u | SORT /unique /o C:\work\unique_play.m3uSort a file playlist.m3u and output only the unique values to a file C:\work\unique_play.m3u
MOREDisplay contents of one or more files, one screen at a time.
ASSOCDisplay or change the association between a file extension and a file type
NOTEPADOpen the Notepad application from cmd
NOTEPAD filename.extOpen a file filename.ext in Notepad

Disk Management

It’s easy to handle and automate the following tasks on cmd.

CommandExplanation
CHKDSKCheck and repair disk problems (local disks only)
CHKDSK /F A:Fix errors on A: drive
CHKDSK /R A:Recover data on A: drive
CHKDSK /X A:Dismount drive A:
CIPHER /E classifiedEncrypt the folder classified
CIPHER /D secret_recipe.txtDecrypt the file secret_recipe.txt
DEFRAGDisk Defragmentation
CHKNTFSDisplay/modify disk-checking on startup
COMPACTDisplay/change the compression of files in NTFS partitions
CONVERTConvert FAT disk volume to NTFS
DISKPARTDisplay and adjust disk partition properties
FORMATFormat the disk
FSUTILFile system management
LABEL d:xRename disk D:\ to X:\
SUBST p: c:\taxesAssign drive P:\ to the local folder c:\taxes
SUBST p: /DRemove the path represented by P:\
RECOVER d:\data.datRecover a file data.dat from a bad or defective disk D:\
VOLDisplay current disk volume label and serial number
POWERCFGControl power settings and configure Hibernate/Standby modes
SFC /SCANNOWScan and update protected system files

Windows Command Generator

Say goodbye to the hassle of trying to remember the exact syntax for the Windows command line! With our Windows Command Generator, you can simply say what you need Windows to do, and we will generate the command for you.

System Information and Networking

The following commands are helpful in troubleshooting computers and computer networks.

CommandExplanation
VERDisplay the current operating system version
SYSTEMINFOList system configuration
HOSTNAMEShow the computer’s hostname on the network
DRIVERQUERYShow all installed device drivers
DATEDisplay/set system date
TIMEDisplay/set system time
GPRESULTDisplay Resultant Set of Policy (RSoP) information for a remote user and computer.
GPUPDATEUpdate group policies
IPCONFIGDisplay Windows IP network configurations
IPCONFIG /releaseRelease your current local IP address
IPCONFIG /renewRequest a new local IP address
IPCONFIG /flushdnsReset the contents of the DNS client resolver cache
PING google.comSend ICMP requests to the target google.com and check host availability
PATHPINGTrace route and provide network latency and packet loss for each router and link in the path
NETProvide various network services
NET use M: \\gameServ /user:"ReadyPlayerOne" player1Assign as disk M:\ the path \\gameServ, logging in as “ReadyPlayerOne” and password “player1
TRACERTFind the IP address of any remote host
NSLOOKUPFind IP addresses on a nameserver
ROUTEManipulate network routing tables
ROUTE PRINTDisplays network route details
ARP -AList IP addresses and corresponding physical addresses (Address Resolution Protocol)
NETSHConfigure network interfaces, Windows firewall, routing, and remote access
NETSTATDisplay current TCP/IP network connections and protocol statistics
GETMACShows all MAC addresses of the network adapters

Process Management

The commands below are Task Manager-like functions. Note that you call variables in arithmetic or logical expressions by enclosing each with two “%” signs (e.g., “%a%”).

CommandExplanation
SCHTASKSCreate/edit a job on Task Scheduler. Use this to create scheduled tasks in Disk Management.
SETList environment variables
PATHDisplay/change the list of folders stored in the %PATH% environment variable
SHUTDOWN /RRestart the computer
SHUTDOWN /S /T 60Shut down the computer 60 seconds from now
TASKLISTList running tasks
TASKLIST /SVCShow services related to each task
TASKLIST /VDisplay detailed task information
TASKLIST | FIND "1234"Get the name of the executable associated with the process ID (PID) of 1234
TASKKILLEnd one or more tasks
TASKKILL /IM "msedge.exe"Terminate all Microsoft Edge instances:
TASKKILL /PID 10736Terminate process with PID of 10736
REGREGEDITRegistry Editor
RUNAS /USER:user2 program1Execute a program program1 as another user user2
POWERSHELLOpen a Powershell instance

Batch Scripting

These commands are for constructing and debugging batch scripts (.bat). To suppress the output of a certain command, add @ in front of it, e.g., @echo off.

Demonstration of CHOICE, PAUSE, and TIMEOUT
CommandExplanation
REM comment. . .
:comment. . .
Prefix for the single-line comment “comment. . .”
GOTO end
<comment_block>
:end
Format of multi-line comments represented by <comment_block> enclosed by delimiters end and :end
SET /A c = %a% + %b%Assign the arithmetic expression a+b to the variable c
^Escape character
some_command > output.txtRedirect output of some_command to a file output.txt
?Wildcard representing one character
*Wildcard representing multiple characters
&Introduce a new command on the same line
TIMEOUT 3600Tell the command prompt to sleep for 3600 seconds (= 1 hour)
PAUSEPrompt the user to continue
CHOICEPrompt the user to pick an on-screen option
CHOICE /T 15 /C ync /CS /D y /M "Press y=Yes, n=No, c=cancel:"You have 15 seconds to press Y, N, or C keys without capitalization, defaulting to “y” if time runs out without a decision
CLSClear screen
CMDRestarts Windows command prompt window:
COLORSet text and background color of cmd:
ECHO ONDisplay each command executed
ECHO OFFOnly display command output
ECHO a string of charactersDisplay a string of characters
HELPDisplay help
PROMPT topSecret^>$$Changes the command line prompt to topSecret>$ for the current session
PROMPTReset the command line prompt to default
START XStart/open a program/document X in a new window
TITLE top SecretSet the title of the current session of Windows command prompt to top Secret
/?Add this to the end of any command word (shown in ALL CAPS in this cheat sheet) to get help on the command, e.g., CD/? = manual for CD (change directory) command
| CLIPAppend this to the end of a command to copy the command output to the clipboard
EXITExits the command line

Flow Control

Note the condition is a Boolean expression e.g., %a%==5.

ConditionalSyntax
IfIF (condition) do_something
If-elseIf (condition) (do_something)
ELSE (do_something_else)
Nested ifIF (condition1) IF (condition2) do_something
Infinite loop:marker
do_something
GOTO marker
While loop:marker
IF (condition) (
   do_something
   GOTO :marker
)

Shortcut keys

Any Windows CLI cheat sheet must include methods to speed up your work, such as the following.

KeyEffect
TabAutocomplete
Ctrl+FFind text in console (opens dialog box)
F1, F3, F5, F8Retype command
F2Copy the current command leftward of the cursor
F4Delete the current command rightward of the cursor
F6Insert end-of-file character
F7List previous commands from which you choose
F9Retype a command by typing its line number in the command history

Conclusion

We sincerely hope this Windows cmd commands cheat sheet helps you finish your work quickly and efficiently today, especially if you’re prone to confusing Windows command prompt commands with other terminal scripting languages in the past.

Remember to check out our course offerings on Windows.

Frequently Asked Questions

Level Up in Cyber Security: Join Our Membership Today!

vip cta image
vip cta details
  • Cassandra Lee

    Cassandra is a writer, artist, musician, and technologist who makes connections across disciplines: cyber security, writing/journalism, art/design, music, mathematics, technology, education, psychology, and more. She's been a vocal advocate for girls and women in STEM since the 2010s, having written for Huffington Post, International Mathematical Olympiad 2016, and Ada Lovelace Day, and she's honored to join StationX. You can find Cassandra on LinkedIn and Linktree.

>