Top Windows Command Line Cheat Sheet
Top Windows Command Line Cheat Sheet
Disk Management
It’s easy to handle and automate the following tasks on cmd.
COMMAND EXPLANATION
CHKDSK Check 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 classified Encrypt the folder classified
CIPHER /D secret_recipe.txt Decrypt the file secret_recipe.txt
DEFRAG Disk Defragmentation
CHKNTFS Display/modify disk-checking on startup
COMPACT Display/change the compression of files in NTFS partitions
CONVERT Convert FAT disk volume to NTFS
DISKPART Display and adjust disk partition properties
FORMAT Format the disk
FSUTIL File system management
LABEL d:x Rename disk D:\ to X:\
SUBST p: c:\taxes Assign drive P:\ to the local folder c:\taxes
SUBST p: /D Remove the path represented by P:\
RECOVER d:\data.dat Recover a file data.dat from a bad or defective disk D:\
VOL Display current disk volume label and serial number
POWERCFG Control power settings and configure Hibernate/Standby modes
SFC /SCANNOW Scan and update protected system files
COMMAND EXPLANATION
VER Display the current operating system version
SYSTEMINFO List system configuration
HOSTNAME Show the computer’s hostname on the network
DRIVERQUERY Show all installed device drivers
DATE Display/set system date
TIME Display/set system time
GPRESULT Display Resultant Set of Policy (RSoP) information for a remote
user and computer.
GPUPDATE Update group policies
IPCONFIG Display Windows IP network configurations
IPCONFIG /release Release your current local IP address
IPCONFIG /renew Request a new local IP address
IPCONFIG /flushdns Reset the contents of the DNS client resolver cache
PING google.com Send ICMP requests to the target google.com and check host
availability
PATHPING Trace route and provide network latency and packet loss for
each router and link in the path
NET Provide various network services
NET use M: \\gameServ Assign as disk M:\ the path \\gameServ, logging in as
/user:"ReadyPlayerOne" player1 “ReadyPlayerOne” and password “player1”
TRACERT Find the IP address of any remote host
NSLOOKUP Find IP addresses on a nameserver
ROUTE Manipulate network routing tables
ROUTE PRINT Displays network route details
ARP -A List IP addresses and corresponding physical addresses
(Address Resolution Protocol)
NETSH Configure network interfaces, Windows firewall, routing, and
remote access
NETSTAT Display current TCP/IP network connections and protocol
statistics
GETMAC Shows 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%”).
COMMAND EXPLANATION
SCHTASKS Create/edit a job on Task Scheduler. Use this to create scheduled tasks in Disk
Management.
SET List environment variables
PATH Display/change the list of folders stored in the %PATH% environment variable
SHUTDOWN Restart the computer
/R
SHUTDOWN Shut down the computer 60 seconds from now
/S /T 60
TASKLIST List running tasks
TASKLIST Show services related to each task
/SVC
TASKLIST /V Display detailed task information
TASKLIST | Get the name of the executable associated with the process ID (PID) of 1234
FIND "1234"
TASKKILL End one or more tasks
TASKKILL Terminate all Microsoft Edge instances:
/IM
"msedge.exe
"
Flow Control
Note the condition is a Boolean expression e.g., %a%==5.
CONDITIONA SYNTAX
L
If IF (condition) do_something
If-else If (condition) (do_something)
ELSE (do_something_else)
Nested if IF (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.
KEY EFFECT
Tab Autocomplete
Ctrl+F Find text in console (opens dialog box)
F1, F3, F5, F8 Retype command
F2 Copy the current command leftward of the cursor
F4 Delete the current command rightward of the cursor
F6 Insert end-of-file character
F7 List previous commands from which you choose
F9 Retype a command by typing its line number in the command history