Windows CMD Cheat Sheet

A quick reference for the Windows Command Prompt, file and folder commands, networking, disk and system tools, plus handy keyboard shortcuts.

A reference for the classic Windows Command Prompt (cmd.exe). Type command /? for built-in help on any command.

Navigating & listing

CommandWhat it does
cdShow the current directory
cd \path\to\dirChange directory (cd .. goes up)
cd /d D:\Change directory and drive
dirList files (dir /a shows hidden)
treeShow the folder structure as a tree
clsClear the screen

Files & folders

CommandWhat it does
type FILEPrint a text file's contents
copy SRC DESTCopy a file
xcopy SRC DEST /E /ICopy folders recursively
robocopy SRC DEST /MIRMirror a folder tree (/E plus /PURGE): deletes files and folders in DEST that no longer exist in SRC
move SRC DESTMove or rename
del FILEDelete a file (/S recursive, /Q quiet)
md NAME / rd NAMEMake / remove a directory (rd needs it empty; rd /s deletes the whole tree)
ren OLD NEWRename a file

System & processes

CommandWhat it does
tasklistList running processes
taskkill /IM name.exe /FForce-kill a process by name
taskkill /PID 1234 /FForce-kill by process ID
systeminfoDetailed OS and hardware info
sfc /scannowScan and repair system files (needs an administrator Command Prompt)
shutdown /r /t 0Restart now (/s = shut down)

Disks & drives

CommandWhat it does
chkdsk C:Check a drive and report its status (read-only, fixes nothing)
chkdsk C: /fFix file-system errors; on the drive Windows is using, it offers to run at the next restart
chkdsk C: /rAlso find bad sectors and recover readable data (includes /f, much slower)
defrag C: /OOptimize a drive the right way for its type (defragment a hard disk, retrim an SSD)
DISM /Online /Cleanup-Image /RestoreHealthRepair the Windows image, then run sfc /scannow again

These need an administrator Command Prompt (right-click, Run as administrator).

Networking

CommandWhat it does
ipconfig /allShow full network configuration
ipconfig /flushdnsClear the DNS resolver cache
ping HOSTTest connectivity to a host
tracert HOSTTrace the route packets take
nslookup DOMAINLook up DNS records
netstat -anoActive connections with owning PID

Pipes, redirection & chaining

SyntaxWhat it does
CMD > fileRedirect output to a file (>> appends)
CMD1 | CMD2Pipe output into another command
CMD1 && CMD2Run CMD2 only if CMD1 succeeds
find "text" fileSearch for text within a file
setShow / set environment variables

Keyboard shortcuts

KeysWhat it does
TabComplete a file or folder name (Tab is the default completion key)
↑ / ↓Recall the previous / next command
F7Pick from a list of this session’s commands
F8Cycle through earlier commands that start with what you’ve typed
EscClear the current line
Ctrl+← / Ctrl+→Move the cursor one word back / forward
Ctrl+CCancel the running command

For modern scripting, see the PowerShell cheat sheet.

What this does

A Windows CMD cheat sheet collects the most useful Command Prompt commands — files and folders, networking, disk and system tools, plus handy shortcuts.

How to use it

  1. Browse by section.
  2. Find the command you need.
  3. Copy it with one tap.
  4. Run it in Command Prompt.

Example

ipconfig /all shows every network adapter’s full configuration.

Last updated .

Frequently asked questions

How do I open the Command Prompt?

Press Win+R, type cmd, and press Enter. For commands that change the system, right-click Command Prompt in the Start menu and select "Run as administrator".

Should I use CMD or PowerShell?

CMD is simpler and great for quick, classic commands. PowerShell is far more powerful for scripting and object-based output, see our PowerShell cheat sheet.

How do I get help for a command?

Type the command followed by /? (for example, dir /?) to see its options and usage.