Windows Command Prompt Cheat Sheet
The classic Windows shell. Commands are not case-sensitive. Add /? to any command for help (for example dir /?).
On this page
Navigation #
| Command | Action |
|---|---|
| Show the current folder | |
| / / | Enter a folder / go up / go to the drive root |
| Change drive and folder at the same time | |
D: | Switch to drive D |
| List files | |
| List including hidden and system files | |
| Search subfolders for .txt files | |
| Bare list (names only) | |
| Folder tree including files | |
| / | Jump to a folder and back again |
cls | Clear the screen |
Files & Folders #
| Command | Action |
|---|---|
| or | Create a folder (creates parent folders as well) |
| Delete a folder and everything in it | |
| Copy a file | |
| Copy a folder with its subfolders | |
| Robust copy (resumes, retries; best for large copies) | |
| Mirror (deletes extra files in dst, so be careful) | |
| Move a file | |
| Rename | |
| Delete a file | |
| Delete matching files in all subfolders | |
| Print a file | |
| Print a file page by page | |
| Write to a file (overwrites) | |
Hide a file (-h to unhide) | |
| Create a symbolic link to a folder (needs admin) |
Search #
| Command | Action |
|---|---|
| Find where a program is located | |
| Search text in files (recursive, ignore case) | |
| Count lines containing the text | |
| Filter command output |
System & Processes #
| Command | Action |
|---|---|
| OS, RAM, install date, hotfixes | |
| / | Computer name / current user |
| Running processes | |
| Kill a process by name | |
| Kill a process by PID | |
| Shut down now | |
| Restart now | |
| Abort a scheduled shutdown | |
| Repair system files (admin) | |
| Check the disk for errors (admin) | |
| Install software with the Windows package manager | |
| Update all installed software |
Network #
| Command | Action |
|---|---|
| IP addresses | |
| Full details (MAC, DNS, DHCP) | |
| Clear the DNS cache | |
+ /renew | Get a new IP from DHCP |
Test connection (-t = keep pinging until stopped) | |
| Show the route to a host | |
| DNS lookup | |
| Open ports with their process IDs | |
| HTTP request (built in on Windows 10+) |
Environment Variables #
| Command | Action |
|---|---|
| List all variables | |
| Print a variable | |
| Set for this session only | |
setx NAME "value" | Set permanently (takes effect in new windows) |
Redirection & Chaining #
| Syntax | Meaning |
|---|---|
cmd > file | Send output to a file (overwrite) |
cmd >> file | Append to a file |
cmd 2> err.txt | Send errors to a file |
cmd > out.txt 2>&1 | Send output and errors to the same file |
cmd > nul | Discard output |
a | b | Pipe output of a into b |
a && b | Run b only if a succeeds |
a || b | Run b only if a fails |
a & b | Run both, always |
Keyboard #
| Key | Action |
|---|---|
Tab | Autocomplete file or folder name |
↑ / ↓ | Previous / next command |
F7 | Command history popup |
Esc | Clear the current line |
Ctrl + C | Stop the running command |
Tips #
- Type
cmdin the File Explorer address bar to open a prompt in that folder. start .opens the current folder in Explorer.start https://siteopens a URL.- Run as administrator:
Win + X→ Terminal (Admin), or right-click → Run as administrator.
cdalso: chdirShow or change the current folder. cd [/d] [drive:][path]
| Usage / option | What it does |
|---|---|
cd | Print the current folder |
cd folder / cd .. / cd \ | Go into a folder / up / to the drive root |
/d | Also change the drive: cd /d D:\Projects |
D: | Switch drive only |
cd "C:\Program Files" | Quotes for paths with spaces |
dirList files and folders. dir [path] [options]
| Option | What it does |
|---|---|
/a | All files, including hidden and system |
/a:d / /a:-d | Folders only / files only (h hidden, s system, r read-only) |
/s | Include all subfolders |
/b | Bare format: names only |
/o:n | Sort by name (s size, d date, e extension, - reverses: /o:-d) |
/t:w | Which date to show: c created, a accessed, w written |
/p | Pause after every screen |
/w | Wide list (several columns) |
/q | Show the owner |
/x | Show short 8.3 names |
/4 | Four-digit years |
Example: dir /s /b *.log lists every log file below this folder.
treeShow the folder structure. tree [path] [/f] [/a]
| Option | What it does |
|---|---|
/f | Include files, not only folders |
/a | Plain ASCII lines (good for copying into text files) |
tree /f > tree.txt | Save the tree to a file |
pushdalso: popdRemember a folder and come back to it.
| Usage | What it does |
|---|---|
pushd C:\temp | Go to a folder and remember where you were |
popd | Return to the remembered folder |
pushd \\server\share | Maps a network share to a free drive letter temporarily |
mkdiralso: mdCreate a folder (parent folders are created automatically). mkdir path
| Usage | What it does |
|---|---|
mkdir name | One folder |
mkdir a\b\c | Nested folders in one go |
mkdir one two three | Several folders |
rmdiralso: rdDelete folders. rmdir [/s] [/q] path
| Option | What it does |
|---|---|
| (none) | Only deletes an empty folder |
/s | Delete the folder and everything in it |
/q | Quiet: don't ask for confirmation |
copyCopy files (not folders). copy [options] source destination
| Option | What it does |
|---|---|
/y | Overwrite without asking |
/-y | Ask before overwriting |
/v | Verify the copy |
/z | Restartable mode (network copies) |
/b | Binary copy |
copy a.txt + b.txt all.txt | Join files |
copy *.txt D:\backup\ | Wildcards |
xcopyCopy files and folder trees (older tool; robocopy is better). xcopy source destination [options]
| Option | What it does |
|---|---|
/e | Include all subfolders, also empty ones |
/s | Subfolders, but skip empty ones |
/i | Destination is a folder (don't ask "file or directory?") |
/h | Include hidden and system files |
/y | Overwrite without asking |
/d | Only files newer than the destination (/d:10-01-2026 = changed on or after Oct 1, format MM-DD-YYYY) |
/c | Continue on errors |
/q / /f | Quiet / show full paths |
/k | Keep the read-only attribute |
/exclude:list.txt | Skip files listed in a file |
/t | Copy the folder structure only, no files |
/j | Unbuffered copy (very large files) |
robocopyRobust copy and mirror tool. robocopy source destination [files] [options]
| Option | What it does |
|---|---|
/e | All subfolders, including empty ones |
/s | Subfolders, skip empty ones |
/mir | ⚠ Mirror: like /e but also deletes files that are gone from the source |
/purge | Delete destination files that no longer exist in the source |
/mov / /move | Move files / files and folders |
/z | Restartable mode (resume after network drops) |
/b | Backup mode (copy files you normally can't access, admin) |
/mt:16 | Multi-threaded: 16 files at once (default 8) |
/r:3 /w:5 | Retry 3 times, wait 5 s (default is 1 million retries!) |
/xf *.tmp | Exclude files |
/xd node_modules .git | Exclude folders |
/xo | Skip files that are older than the destination |
/l | List only: show what would happen |
/log:copy.log / /tee | Write a log file / also show output on screen |
/np | No percentage progress |
/copy:DAT | What to copy: Data, Attributes, Timestamps (S security, O owner) |
/dcopy:DAT | Same for folders |
/xj | Skip junction points |
Exit codes below 8 mean success (1 = files copied).
moveMove or rename files and folders. move [/y | /-y] source destination
| Option | What it does |
|---|---|
/y | Overwrite without asking |
/-y | Ask before overwriting |
move *.log logs\ | Wildcards |
renalso: renameRename files or folders (same location). ren oldname newname
| Usage | What it does |
|---|---|
ren old.txt new.txt | Rename one file |
ren *.txt *.md | Change the extension of every .txt file |
ren "My File.txt" file.txt | Quotes for names with spaces |
delalso: eraseDelete files (not folders). del [options] files
| Option | What it does |
|---|---|
/s | Also in all subfolders |
/q | Quiet: don't ask for wildcards |
/f | Also delete read-only files |
/p | Ask for every file |
/a:h | Select by attribute (h hidden, s system, r read-only) |
Deleted files skip the Recycle Bin.
typePrint a text file. type file…
| Usage | What it does |
|---|---|
type file.txt | Show a file |
type a.txt b.txt > all.txt | Join files |
type file.txt | more | Page through a long file |
type nul > empty.txt | Create an empty file |
moreShow output one screen at a time. more [options] [file]
| Option / key | What it does |
|---|---|
more file.txt / command | more | Page through a file / output |
+20 | Start at line 20 |
/s | Squeeze multiple empty lines into one |
/c | Clear the screen before each page |
/t4 | Expand tabs to 4 spaces |
Space / Enter | Next page / next line |
q | Quit |
echoPrint text or turn command echo on/off. echo [text | on | off]
| Usage | What it does |
|---|---|
echo Hello | Print text |
echo. | Print an empty line |
echo %PATH% | Print a variable |
echo text > file.txt | Write to a file (>> appends) |
@echo off | First line of batch files: don't show the commands |
attribShow or change file attributes. attrib [+/-attr] [path] [/s] [/d]
| Option | What it does |
|---|---|
+h / -h | Hidden on / off |
+r / -r | Read-only on / off |
+s / -s | System file on / off |
+a / -a | Archive flag on / off |
/s | Include files in subfolders |
/d | Include folders too |
attrib -h -s -r *.* /s /d | Unhide everything (e.g. after a USB virus) |
mklinkCreate symbolic links, hard links and junctions (needs admin or Developer Mode). mklink [option] link target
| Option | What it does |
|---|---|
| (none) | Symbolic link to a file |
/d | Symbolic link to a folder |
/h | Hard link to a file |
/j | Directory junction (works without admin rights) |
Note the order: the new link first, then the existing target.
whereFind where a program or file is. where [options] pattern
| Option | What it does |
|---|---|
where python | Every python in PATH (the first one runs) |
/r C:\dev *.sln | Search a folder recursively |
/q | Quiet: only the exit code |
/f | Put the results in quotes |
/t | Show size and date too |
findstrSearch text in files (cmd's grep). findstr [options] "text" files
| Option | What it does |
|---|---|
/s | Search subfolders |
/i | Ignore case |
/n | Show line numbers |
/v | Lines that do not match |
/m | Only the names of matching files |
/c:"exact phrase" | Search a phrase with spaces (otherwise each word is an OR) |
/r | Regular expression (basic) |
/l | Literal text, no regex |
/b / /e | Match at the beginning / end of a line |
/x | Whole line must match |
/p | Skip binary files |
/g:words.txt | Read the search strings from a file |
Example: netstat -ano | findstr :3000
findSearch for a text in files or output (simple). find [options] "text" [file]
| Option | What it does |
|---|---|
/i | Ignore case |
/c | Only count matching lines |
/n | Show line numbers |
/v | Lines without the text |
The text must be in double quotes. For more power use findstr.
systeminfoDetailed information about Windows and the hardware. systeminfo [options]
| Option | What it does |
|---|---|
/fo list | Output as a list (table or csv) |
/nh | No column headers (with table / csv) |
/s PC01 | Another computer |
systeminfo | findstr /c:"OS Name" /c:"Total Physical Memory" | Pick out a few lines |
hostnamePrint the computer name. No options; change it in Settings → System → About → Rename this PC.
| Usage | What it does |
|---|---|
hostname | Computer name |
whoamiWho you are logged in as. whoami [options]
| Option | What it does |
|---|---|
| (none) | computer\user |
/upn | Your sign-in name (Microsoft / work account) |
/user | User name and SID |
/groups | Your groups |
/priv | Your privileges |
/all | Everything |
tasklistList running programs. tasklist [options]
| Option | What it does |
|---|---|
/v | Verbose: window titles, CPU time, user |
/svc | Services inside each process |
/m dll | Processes that use a module |
/fi "imagename eq chrome.exe" | Filter (pid eq 1234, memusage gt 500000, status eq not responding) |
/fo csv | Output format (table, list, csv) |
/nh | No headers |
/s PC01 | Another computer |
taskkillEnd programs. taskkill [options]
| Option | What it does |
|---|---|
/im app.exe | By image name (* wildcard only works together with a /fi filter) |
/pid 1234 | By process ID |
/f | Force (needed for most stuck programs) |
/t | Also end child processes |
/fi "status eq not responding" | Filter, like tasklist |
/s PC01 | Another computer |
shutdownShut down, restart or log off. shutdown [options]
| Option | What it does |
|---|---|
/s | Shut down |
/r | Restart |
/l | Log off |
/h | Hibernate |
/a | Abort a scheduled shutdown |
/t 60 | Wait 60 seconds (/t 0 = now) |
/f | Force running programs to close |
/c "Updating" | Message to show |
/g | Restart and reopen registered apps |
/r /o | Restart into the advanced boot options menu |
/r /fw | Restart into the BIOS / UEFI setup |
sfcSystem File Checker: repairs damaged Windows files (admin). sfc [option]
| Option | What it does |
|---|---|
/scannow | Scan and repair all protected system files |
/verifyonly | Scan, don't repair |
/scanfile=C:\path\file | Scan and repair one file |
/verifyfile=C:\path\file | Check one file |
If it can't repair everything, first run DISM /Online /Cleanup-Image /RestoreHealth, then sfc /scannow again.
chkdskCheck a drive for file-system errors and bad sectors (admin). chkdsk [drive:] [options]
| Option | What it does |
|---|---|
| (none) | Read-only check |
/f | Fix errors (system drive: runs at the next restart) |
/r | Find bad sectors and recover data (includes /f, slow) |
/x | Force the drive to dismount first |
/scan | Online scan while the drive is in use (NTFS) |
/spotfix | Quick fix of found problems (NTFS) |
wingetWindows Package Manager. winget command [options]
| Command / option | What it does |
|---|---|
search name | Find packages |
install name | Install (--id Git.Git -e = exact ID, safest) |
upgrade | List available updates |
upgrade --all | Update everything (--include-unknown for apps without version info) |
uninstall name | Remove |
list | Installed apps (--upgrade-available for outdated ones) |
show name | Details and versions |
export -o apps.json / import -i apps.json | Move your app list to another PC |
pin add name | Don't upgrade this app |
--silent | No installer windows |
--scope user / machine | Install for you / for all users |
-v 1.2.3 | Specific version |
--accept-package-agreements --accept-source-agreements | No license prompts (scripts) |
ipconfigNetwork configuration. ipconfig [option]
| Option | What it does |
|---|---|
| (none) | IP address, subnet mask, gateway per adapter |
/all | Everything: MAC address, DNS servers, DHCP, lease times |
/release / /renew | Drop / request a new IPv4 address from DHCP |
/release6 / /renew6 | Same for IPv6 |
/flushdns | Clear the DNS cache (fixes many "site not found" issues) |
/displaydns | Show the DNS cache |
/registerdns | Refresh DHCP and re-register the DNS name |
pingCheck whether a host answers (Windows version). ping [options] host
| Option | What it does |
|---|---|
-t | Keep pinging until Ctrl + C |
-n 10 | Send 10 pings (default 4) |
-l 1400 | Packet size in bytes |
-w 2000 | Timeout per reply in ms |
-i 64 | Time to live (TTL) |
-a | Resolve the IP address to a host name |
-4 / -6 | Force IPv4 / IPv6 |
tracertShow every router between you and a host. tracert [options] host
| Option | What it does |
|---|---|
-d | Don't resolve names (much faster) |
-h 20 | At most 20 hops |
-w 1000 | Timeout per reply in ms |
-4 / -6 | Force IPv4 / IPv6 |
pathping host combines tracert with packet-loss statistics.
nslookupDNS lookup. nslookup [-option] name [server]
| Usage / option | What it does |
|---|---|
nslookup example.com | IP address(es) of a name |
nslookup example.com 1.1.1.1 | Ask a specific DNS server |
-type=MX | Record type: MX, TXT, NS, AAAA, CNAME, SOA |
nslookup 8.8.8.8 | Reverse lookup |
nslookup (no name) | Interactive mode: set type=mx, then names; exit to leave |
netstatNetwork connections and listening ports. netstat [options] [interval]
| Option | What it does |
|---|---|
-a | All connections and listening ports |
-n | Numbers instead of names (fast) |
-o | Show the process ID (PID) |
-b | Show the program name (admin) |
-p tcp | Only one protocol |
-r | Routing table |
-e | Ethernet statistics |
-s | Statistics per protocol |
netstat -ano 5 | Repeat every 5 seconds |
Who uses port 3000? netstat -ano | findstr :3000, then tasklist /fi "pid eq 1234".
curlTransfer data with URLs: download files, call APIs. curl [options] URL
| Option | What it does |
|---|---|
-o file | Save to a file with that name |
-O | Save with the name from the URL |
-L | Follow redirects |
-I | Headers only (HEAD request) |
-i | Include response headers in the output |
-v | Verbose: show the full request and response |
-s / -sS | Silent / silent but still show errors |
-f, --fail | Exit with an error on HTTP 4xx/5xx |
-X POST | HTTP method (PUT, DELETE, PATCH…) |
-H "Authorization: Bearer $TOKEN" | Add a header |
-d '{"a":1}' | Send data (makes it a POST) |
--json '{"a":1}' | Send JSON with the right headers (curl 7.82+) |
-F "file=@photo.jpg" | Upload a file as a form |
-u user:pass | Basic authentication |
-k | Ignore TLS certificate errors (testing only!) |
-C - | Resume a broken download |
--max-time 10 | Give up after 10 seconds |
--retry 3 | Retry on temporary errors |
-w "%{http_code}\n" | Print details such as the status code |
-b / -c cookies.txt | Send / save cookies |
-x http://proxy:8080 | Use a proxy |
--compressed | Ask for and decompress gzip/brotli responses |
Windows 10+ has real curl too (in PowerShell type curl.exe, because curl is an alias there).
setShow or set environment variables for this window. set [name[=value]]
| Usage | What it does |
|---|---|
set | List all variables |
set P | Variables starting with "P" |
set NAME=value | Set for this window only (no spaces around =) |
set NAME= | Remove a variable |
set /a X=5*2 | Arithmetic |
set /p NAME=Your name? | Ask the user for input (batch files) |
Nothing on this sheet matches “”.