Windows Command Line Cheat Sheet

The cmd and PowerShell commands you will actually use, each with a one-line description. Print it and keep it by your keyboard.

Windows has two command shells: Command Prompt (cmd), the older shell, and PowerShell, the newer one. Both are built into Windows, and both open from the Start menu or with Win+X. Every command below is real and ships with Windows. Run Command Prompt or PowerShell as administrator for commands that change system settings.

Files and folders, Command Prompt

CommandWhat it does
dirLists the files and folders in the current folder
cd folderMoves into a folder; cd .. moves up one level
mkdir nameCreates a new folder
rmdir nameDeletes an empty folder; add /s to delete it with its contents
copy source destinationCopies a file
move source destinationMoves a file, or renames it when the destination is a new name in the same folder
ren old newRenames a file or folder
del fileDeletes a file
type fileShows the contents of a text file
treeShows the folder structure as a tree
attrib fileShows or changes file attributes such as read-only and hidden
xcopy source destinationCopies files and folders, including subfolders with /s
robocopy source destinationCopies whole folders reliably, with resume and mirroring options

Files and folders, PowerShell

CommandWhat it does
Get-ChildItemLists files and folders; the alias ls works too
Set-Location folderMoves into a folder; the alias cd works too
New-Item -ItemType Directory -Name nameCreates a new folder
Copy-Item source destinationCopies a file or folder
Move-Item source destinationMoves or renames a file or folder
Remove-Item fileDeletes a file or folder; add -Recurse for a folder with contents
Rename-Item old newRenames a file or folder
Get-Content fileShows the contents of a text file; the alias cat works too
Set-Content file -Value "text"Writes text into a file, replacing what was there
Test-Path pathChecks whether a file or folder exists, returning True or False

Network

CommandShellWhat it does
ipconfigcmdShows your IP address, subnet mask, and gateway
ipconfig /allcmdShows full network details, including DNS servers and MAC address
ipconfig /flushdnscmdClears the DNS cache, which can fix sites that load the wrong address
ping addresscmdChecks whether a computer or site responds, and how fast
tracert addresscmdShows each hop a connection takes to reach an address
nslookup domaincmdLooks up the IP address for a domain name
netstat -anocmdLists open connections and which process owns each one
Test-Connection addressPowerShellPowerShell version of ping, with richer output
Get-NetIPAddressPowerShellShows the IP addresses on this computer
Get-NetAdapterPowerShellLists network adapters and their status

System info and processes

CommandShellWhat it does
systeminfocmdShows Windows version, install date, memory, and more
hostnamecmdShows this computer's name
whoamicmdShows the current user name
vercmdShows the Windows version number
tasklistcmdLists running processes
taskkill /PID id /FcmdForce-stops the process with the given ID; find the ID with tasklist
sfc /scannowcmd, as adminScans and repairs protected Windows system files
chkdsk /fcmd, as adminChecks the disk for errors and fixes them; may ask to run at the next restart
driverquerycmdLists installed device drivers
net usercmdLists the user accounts on this computer
Get-ComputerInfoPowerShellShows detailed system information
Get-ProcessPowerShellLists running processes
Stop-Process -Name namePowerShellStops a running process by name
Get-ServicePowerShellLists Windows services and whether each is running
Get-DiskPowerShellLists physical disks and their size and health status

Power and shutdown

CommandShellWhat it does
shutdown /s /t 0cmdShuts the computer down immediately
shutdown /r /t 0cmdRestarts the computer immediately
shutdown /acmdCancels a shutdown that is counting down
Stop-ComputerPowerShellShuts the computer down
Restart-ComputerPowerShellRestarts the computer
Be careful with delete and format commands. del, Remove-Item, and rmdir /s do not send files to the Recycle Bin. Double-check the path before you press Enter, especially with wildcards such as *.

Common questions

How do I open Command Prompt or PowerShell as administrator? Right-click the Start button and choose Terminal (Admin), or search for Command Prompt or PowerShell in the Start menu, right-click it, and choose Run as administrator. Some commands, such as sfc /scannow and chkdsk /f, only work from an elevated window.

What is the difference between Command Prompt and PowerShell? Command Prompt is the older shell with simple text commands. PowerShell is the newer shell: its commands return structured objects instead of plain text, so you can filter and sort results, and it works across Windows, macOS, and Linux. For everyday file and network checks, either one works.

Why does a command say it is not recognized? The usual causes are a typo, a command that belongs to the other shell, or a program that is not installed or not on the PATH. Check the spelling first, then check whether the command is a cmd command or a PowerShell command.

Related

Keyboard Shortcuts Cheat Sheet · Regex Cheat Sheet · Standard Dimensions Chart

Was this helpful?