Windows Cheatsheet
Command Prompt (CMD) is the classic Windows shell for navigating folders, managing files, and running system utilities.
Paths may use backslashes. Quote paths that contain spaces. PowerShell can run many of the same ideas with different syntax.
Full lessons: Windows Tutorials
CMD basics
Open Command Prompt
Search for cmd, or press Win+R, type cmd, and Enter. Run as administrator only when a task requires it.
Win + R → cmd → Enter
help / /?
List common commands or show help for one command. Many tools accept /?.
help
dir /?
ipconfig /?
cls
Clear the screen so new output is easier to follow.
cls
Command history
Press Up/Down to recall previous lines. doskey /history lists recent commands in the session.
doskey /history
echo & prompt
echo prints text or variable values. Useful when writing and testing batch files.
echo Hello
echo %USERNAME%
echo %CD%
Exit codes
After a command, %ERRORLEVEL% is 0 on success for many tools, nonzero on failure.
dir missing-folder
echo %ERRORLEVEL%
Files & folders
dir
List files and folders. /a shows hidden items; /s includes subfolders; /w is wide view.
dir
dir /a
dir *.txt /s
cd / chdir
Change directory. cd \ goes to the drive root; cd .. goes up one level.
cd %USERPROFILE%\Documents
cd ..
cd /d D:\projects
md / mkdir
Create a new folder. Intermediate folders may need creating step by step in older CMD styles.
mkdir notes
mkdir projects\web
copy / xcopy / robocopy
copy for simple files; robocopy for robust folder backups and mirrors.
copy draft.txt draft.bak
robocopy C:\Data D:\Backup\Data /E
move / ren
Move files between folders or rename them in place.
move report.pdf %USERPROFILE%\Documents\
ren old.txt new.txt
del / rd
Delete files with del; remove empty directories with rd. rd /s removes a tree—confirm carefully.
del temp.log
rd empty-folder
rd /s /q old-build
tree
Show a folder hierarchy as a tree listing.
tree
tree /F C:\projects\demo
Viewing & search
type
Print a text file to the console. For long files, pipe into more.
type readme.txt
type big.log | more
more
Page through output one screen at a time. Press Space for the next page.
more longfile.txt
findstr
Search for text patterns inside files (similar in spirit to grep).
findstr /i "error" app.log
findstr /s /i "TODO" *.py
where
Locate executables on PATH, or find files matching a pattern when used carefully.
where python
where notepad
Pipes & redirection
Pipe with |; write output with >; append with >>.
dir /b | findstr .txt
ipconfig > network.txt
attrib
View or change file attributes such as read-only or hidden.
attrib notes.txt
attrib +R important.cfg
System & processes
systeminfo
Print OS version, memory, hotfixes, and other machine details.
systeminfo
systeminfo | findstr /i "OS Name"
whoami
Show the current user context, including domain\user form on domain-joined PCs.
whoami
whoami /groups
tasklist
List running processes and PIDs. Filter by image name when hunting a specific app.
tasklist
tasklist | findstr /i chrome
taskkill
End a process by PID or image name. Prefer closing apps normally when possible.
taskkill /PID 1234
taskkill /IM notepad.exe
Environment variables
Expand with %NAME%. set lists or sets variables for the current session.
echo %PATH%
set MYDIR=C:\Work
echo %MYDIR%
setx (persistent)
Writes a user or machine environment variable permanently—use sparingly and reopen CMD to see changes.
setx DEMO_PATH C:\Tools\demo
Networking
ipconfig
Show adapter addresses. /all includes DNS and DHCP details; /flushdns clears the DNS cache.
ipconfig
ipconfig /all
ipconfig /flushdns
ping
Test reachability and round-trip time to a host.
ping example.com
ping -n 4 8.8.8.8
tracert
Trace the route packets take toward a destination, hop by hop.
tracert example.com
nslookup
Query DNS for name-to-address (and related) records.
nslookup example.com
nslookup example.com 1.1.1.1
netstat
Inspect active connections and listening ports.
netstat -ano
netstat -ano | findstr :443
Batch tips
@echo off
At the top of a .bat file, hide command echoing so only your messages and results show.
@echo off
echo Starting backup...
Variables
Set with set; expand with %NAME%. Use delayed expansion for values set inside blocks.
@echo off
set NAME=Ada
echo Hello %NAME%
if / exist
Branch on conditions such as file existence or string comparison.
@echo off
if exist notes.txt (
echo Found notes
) else (
echo Missing notes
)
for loops
Iterate files or simple lists. Quote paths with spaces.
@echo off
for %%F in (*.txt) do echo %%F
pause & exit
pause waits for a key (useful when double-clicking a script). exit /b returns from a batch script.
@echo off
echo Done
pause
exit /b 0
Calling other scripts
Use call so control returns to the parent batch file afterward.
@echo off
call setup-env.bat
call build.bat
Comments
One comment per signed-in account. Comments are saved with this page’s URL.