All cheatsheets

Windows CMD Commands Cheat Sheet

Quick reference for the classic Windows Command Prompt (cmd.exe): file/dir operations, text search, system info, networking and batch scripting — with common options and practical examples.

40 commands

Navigation & Help

cd /d <path>

Change current directory; /d also changes the drive letter.

cd /d D:\projects\app
dir [<path>]

List files and subdirectories with size, date and attributes.

/a show hidden/system; /s recurse; /o sort by date/size; /b bare format; /w wide

dir /a /o:-d /b C:\logs
<cmd> /?

Show the built-in help for any command (e.g., 'robocopy /?').

xcopy /?
tree [<path>]

Graphically display the folder structure of a drive or path.

/F include files; /A use ASCII characters; /J Juniper format

tree C:\projects /F | more

Files & Directories

md <dir> (or mkdir)

Create one or more directories.

md C:\app\logs 2>nul
rd <dir> (or rmdir)

Remove (delete) one or more directories.

/s also remove files and subdirs; /q quiet mode (no prompt)

rd /s /q C:\app\tmp
del <pattern>

Delete one or more files.

/f force read-only; /s delete in subdirs; /q quiet; /p prompt per file

del /s /q C:\app\logs\*.log
copy <src> <dest>

Copy one or more files to another location.

/y overwrite without prompt; /v verify; /d decrypt dest; /b binary

copy /y C:\src\config.json D:\app\config.json
move <src> <dest>

Move files and rename files or directories.

/y overwrite; /-y prompt

move /y C:\app\old.log D:\archive\
ren <old> <new>

Rename a file or directory (use only on the filename, not the full path).

ren report.txt report-2026.txt
xcopy <src> <dest>

Copy files, directories, and subdirectories (legacy; superseded by robocopy).

/s /e subdirs; /y overwrite; /i assume dest is dir; /h hidden/system; /d only newer

xcopy /s /e /y /d C:\src D:\dst
robocopy <src> <dest>

Robust file copy for larger jobs, with retry, logging and mirroring.

/MIR mirror; /MOV move (del source); /E subdirs incl empty; /Z restartable; /MT:n multithread; /LOG:<file>; /R:n retries; /W:n wait

robocopy C:\src \\ackup\daily /MIR /Z /MT:8 /LOG+:C:\logs\robocopy.txt
attrib [+/-<attr>] <path>

Change file attributes: Read-only (R), Hidden (H), System (S), Archive (A).

/s recurse; /d process folders; +R -R read-only on/off

attrib +R +H secret\config.ini
mklink [[/D] | /H] <link> <target>

Create a symbolic (/D) or hard (/H) link to a file or directory.

/D directory symlink; /H hard link; /J directory junction

mklink /D C:\current C:\app\v2

Text & Search

type <file>

Display the entire contents of a text file on screen.

type C:\app\config.json | more
more < file

Page output one screen at a time (work like Unix less).

type big.log | more
find "<str>" <files>

Search for a literal string in one or more files (legacy; no regex).

/i case-insensitive; /v invert; /n line numbers; /c count only

find /i /n "TODO" *.md
findstr [/R] <pattern> <files>

Search text with literal strings or regex; supports multiple patterns.

/R regex; /S subdirs; /I case-insensitive; /N line numbers; /M files with matches; /V invert; /C:"text" literal string

findstr /R /S /I /N "TODO\|FIXME" *.cs
sort [/R] [<file>]

Sort input (or file) alphabetically/numerically; sort supports codes via /+N sort key.

/R reverse; /+N sort by char position N; [drive1:][path1] [drive2:][path2] input/output

sort /R /+5 unsorted.txt sorted.txt
fc /b file1 file2

Compare two files; /b compares byte-by-byte (binary).

/b binary compare; /a abbreviated output; /l line-based; /n show line numbers

fc /b file1.bin file2.bin

System & Disk

systeminfo

Detailed configuration about the host, OS, memory, network.

systeminfo /fo csv > sysinfo.csv
tasklist [/FI <filter>]

List running processes with PID, session, memory, image name.

/v verbose; /FI filter (e.g., "IMAGENAME eq cmd.exe"); /M modules

tasklist /FI "IMAGENAME eq node.exe" /FO csv
taskkill /PID <pid> [/F]

Kill a process by PID (or image name, with /IM).

/F force; /IM image name; /PID pid; /T tree (children too); /FI filter

taskkill /IM chrome.exe /F
sc \[\\host] query|start|stop <service>

Communicate with the Service Control Manager; query/config services.

query state= all; start / stop; config starts auto|manual|disabled; create / delete

sc query state= all | more
shutdown [/s|/r|/a]

Log off, restart, or shut down the local/remote computer.

/s shutdown; /r restart; /a abort; /t N seconds; /c "comment"; /m \\host; /f force close apps

shutdown /r /t 60 /c "Windows Update"
diskpart

Interactive disk partitioning utility (run as admin); supports list disk/partition/volume.

list disk / select disk N / clean / create partition primary / format fs=ntfs quick / assign letter=D

diskpart /s script.txt
chkdsk <drive>

Check a disk for errors and recover readable data.

/f fix errors; /r recover bad sectors; /x force dismount; /v verbose

chkdsk D: /f /r /x
vol <drive>:

Show the volume label and serial number of a drive.

vol C:

Networking

ipconfig [/all|/flushdns]

Show TCP/IP configuration; /flushdns clears the DNS client cache.

/all detail; /release / renew DHCP; /flushdns; /displaydns

ipconfig /all && ipconfig /flushdns
ping [-n <count>] <host>

Send ICMP echo requests to test reachability and latency (default 4).

-n count; -t continuous; -l size; -w timeout(ms); -4 / -6 force version

ping -n 6 8.8.8.8
tracert [-d] [-h <hops>] <host>

Trace the route packets take to a host; -d skips reverse DNS.

-h max hops; -w timeout; -d no DNS; -4 / -6

tracert -d -h 15 google.com
nslookup <host>

Query DNS — interactive and non-interactive modes.

server 8.8.8.8; type=A/AAAA/MX/CNAME/TXT; -timeout=N

nslookup example.com 1.1.1.1
netstat [-an] [-b]

Display active TCP/UDP connections, listening ports, and the owning process.

-a all; -b owning exe; -n numeric; -o PID; -p tcp|udp; -r routing table

netstat -ano | findstr :443
net [user|localgroup|share|start|stop|use|time|view]

A huge grab-bag for user accounts, shares, services, mapped drives, etc.

net user <name> /add; net localgroup Administrators; net share; net use x: \\host\share

net user alice P@ssw0rd! /add && net localgroup Administrators alice /add

Batch Scripting

echo [on|off|<text>]

Toggle command echoing or print text without a trailing newline (use set /p instead).

@echo off disables the prefix; & echo. to emit a blank line

@echo off & echo Starting build...
set <var>=<value>

Define or modify an environment variable visible to child processes.

set /P var="prompt" read from stdin; set /A var=expr integer math

set /A total = 5 * 20 + 3
if [/i] [not] <condition> cmd

Conditional execution — strings, numbers, errorlevel, exist files.

if exist file; if %var% == value; if %errorlevel% neq 0; if defined

if exist .git (git status) else (git init)
for /f [...] %%<var> in (...) do <cmd>

Loop constructs: /f (parse text/command output), /r (recurse), /d (dirs), plain (set).

tokens / delims / skip / usebackq for cmd; %%i in interactive scripts vs %i on cmd line

for /f "tokens=2 delims=:" %%p in ('reg query "HKCU\Software\Git" /v InstallPath') do set GIT_HOME=%%p
call <script> [<args>]

Call another batch script and return (vs. plain invocation, which stops the caller).

? shows help; /e:on enable extensions; /v:on delayed expansion

call utils\env.bat && call build\compile.bat
goto / rem / exit

Labels (goto :label), comments (rem), and explicit exit codes.

exit /b <code>; comment blocks with rem ←→ ... reset

exit /b 1

Cheatsheet version 1.0.0

Covers Windows cmd.exe 10+