A comprehensive Microsoft Windows Command Prompt reference covering navigation, files and folders, text processing, environment variables, processes, services,…
A comprehensive Microsoft Windows Command Prompt reference covering navigation, files and folders, text processing, environment variables, processes, services, networking, system administration, troubleshooting, batch scripting, automation, and essential CMD commands.
Table of Contents
Getting Started
Command Prompt, commonly called CMD, is the traditional Windows command-line interpreter. The executable is cmd.exe.
Open Command Prompt:
cmd
Open Command Prompt as administrator:
Start → Command Prompt → Run as administrator
Open CMD from another command:
start cmd
Open an elevated CMD from the Run dialog:
Win + R
cmd
Ctrl + Shift + Enter
Display the current Windows version:
ver
Display the current computer name:
hostname
Display the current user:
whoami
Display the current directory:
cd
List files and folders:
dir
Clear the screen:
cls
Exit Command Prompt:
exit
Your first CMD session
Try these commands in order:
whoami
hostname
cd
dir
ver
Each command produces information about the current Windows environment.
Core Concepts
CMD commands generally follow this structure:
command [options] [arguments]
For example:
dir C:\Users /s /b
Here:
dir Command
C:\Users Argument
/s Option
/b Option
Command chaining
Run two commands regardless of the first command's result:
command1 & command2
Run the second command only if the first succeeds:
command1 && command2
Run the second command only if the first fails:
command1 || command2
Comments in batch files
Use rem for comments:
rem This is a comment
You will also commonly see:
@echo off
This prevents commands themselves from being displayed as the batch file executes.
Getting Help
CMD includes built-in help for most commands.
Display general help:
help
Get help for a specific command:
help dir
The most commonly used form is:
dir /?
Examples:
copy /?
del /?
findstr /?
ipconfig /?
netstat /?
robocopy /?
tasklist /?
Search the list of available commands:
help
Search command output:
help | findstr /i network
Discover command syntax
When you are unsure how a command works, try:
command /?
For example:
robocopy /?
This is particularly useful because options can vary between Windows versions.
File System Navigation
Display the current directory:
cd
Change directory:
cd C:\Users
Change to the root of the current drive:
cd \
Move up one directory:
cd ..
Move up two directories:
cd ..\..
Change drive:
D:
Change drive and directory:
cd /d D:\Projects
Go to the current user's profile:
cd %USERPROFILE%
Go to the temporary directory:
cd %TEMP%
Save the current directory and change location:
pushd C:\Projects
Return to the previously saved directory:
popd
Display a directory tree
tree
Display the tree using ASCII characters:
tree /a
Display files as well as directories:
tree /f
Files and Folders
List files:
dir
List all files, including hidden and system files:
dir /a
List directories only:
dir /ad
List files only:
dir /a-d
Display names only:
dir /b
Display files recursively:
dir /s
Display complete paths recursively:
dir /s /b
List text files:
dir *.txt
List files beginning with report:
dir report*
List files modified today:
dir /od
Sort by size:
dir /o-s
Create a directory:
mkdir Projects
Short form:
md Projects
Create nested directories:
mkdir Projects\2026\September
Remove an empty directory:
rmdir Projects
Short form:
rd Projects
Remove a directory and its contents:
rmdir /s Projects
Remove without confirmation:
rmdir /s /q Projects
Files
Display a text file:
type file.txt
Copy a file:
copy file.txt backup.txt
Move a file:
move file.txt C:\Backup\
Rename a file:
ren old.txt new.txt
Alternative:
rename old.txt new.txt
Delete a file:
del file.txt
Alternative:
erase file.txt
Force deletion of a read-only file:
del /f file.txt
Delete without prompting:
del /q file.txt
Delete all .tmp files:
del *.tmp
Delete files recursively:
del /s *.tmp
File attributes
Display attributes:
attrib file.txt
Remove read-only:
attrib -r file.txt
Hide a file:
attrib +h file.txt
Unhide a file:
attrib -h file.txt
Mark as system file:
attrib +s file.txt
Remove system attribute:
attrib -s file.txt
Copying and Moving Files
Copy one file:
copy source.txt destination.txt
Copy multiple files:
copy *.txt C:\Backup\
Copy a directory tree:
xcopy C:\Source C:\Backup /E
Include hidden and system files:
xcopy C:\Source C:\Backup /E /H
Preserve attributes:
xcopy C:\Source C:\Backup /E /H /K
For larger or more robust directory transfers, use robocopy:
robocopy C:\Source C:\Backup /E
Copy only newer files:
robocopy C:\Source C:\Backup /E /XO
Exclude files:
robocopy C:\Source C:\Backup /E /XF *.tmp
Exclude directories:
robocopy C:\Source C:\Backup /E /XD temp cache
Use restartable mode:
robocopy C:\Source C:\Backup /E /Z
Copy with multiple threads:
robocopy C:\Source C:\Backup /E /MT:8
Mirror a directory:
robocopy C:\Source C:\Backup /MIR
Warning: /MIR can delete files from the destination. Verify the source and destination carefully before using it.
Searching and Filtering
Search for a filename:
dir filename.txt /s /b
Find all Python files:
dir C:\Projects\*.py /s /b
Find an executable:
where python
Find Git:
where git
Find Node.js:
where node
Search for text:
find "error" logfile.txt
Case-insensitive search:
findstr /i "error" logfile.txt
Recursive search:
findstr /s /i "error" *.log
Search multiple words:
findstr /i "error warning failed" logfile.txt
Search for an exact phrase:
findstr /i /c:"connection refused" logfile.txt
Search source code:
findstr /s /i "TODO" *.js *.py *.php
Search all files recursively:
findstr /s /i "database" *.*
Working with Text
Display a file:
type file.txt
Display a file page by page:
type file.txt | more
Use more directly:
more file.txt
Sort text:
sort file.txt
Compare two text files:
fc file1.txt file2.txt
Binary comparison:
fc /b file1.bin file2.bin
Search text:
find "keyword" file.txt
Advanced search:
findstr /i "keyword" file.txt
Copy output to the clipboard:
type file.txt | clip
Copy a directory listing:
dir /s /b | clip
Copy network information:
ipconfig /all | clip
Environment Variables
Display all environment variables:
set
Display one variable:
echo %PATH%
Set a temporary variable:
set NAME=Michael
Read a variable:
echo %NAME%
Delete a variable:
set NAME=
Set a persistent user environment variable:
setx NAME "Michael"
Common environment variables
| Variable |
Meaning |
%PATH% |
Executable search path |
%TEMP% |
Temporary directory |
%TMP% |
Temporary directory |
%USERPROFILE% |
Current user's profile |
%USERNAME% |
Current username |
%COMPUTERNAME% |
Computer name |
%SystemRoot% |
Windows directory |
%WINDIR% |
Windows directory |
%ProgramFiles% |
Program Files directory |
%ProgramData% |
ProgramData directory |
%APPDATA% |
Roaming application data |
%LOCALAPPDATA% |
Local application data |
%CD% |
Current directory |
%DATE% |
Current date |
%TIME% |
Current time |
%ERRORLEVEL% |
Previous command's exit code |
Display several variables
echo User: %USERNAME%
echo Computer: %COMPUTERNAME%
echo Directory: %CD%
echo Windows: %SystemRoot%
Operators and Redirection
Command chaining
Run commands sequentially:
command1 & command2
Run the second command only after success:
command1 && command2
Run the second command only after failure:
command1 || command2
Pipes
Send the output of one command to another:
tasklist | findstr chrome
Find listening ports:
netstat -ano | findstr LISTENING
Output redirection
Overwrite a file:
dir > files.txt
Append to a file:
dir >> files.txt
Redirect errors:
command 2> errors.txt
Redirect output and errors:
command > output.txt 2>&1
Discard standard output:
command > nul
Discard errors:
command 2> nul
Discard both:
command > nul 2>&1
Processes and Applications
List running processes:
tasklist
Detailed process information:
tasklist /v
Find a process:
tasklist | findstr /i chrome
Terminate a process by name:
taskkill /im notepad.exe
Force termination:
taskkill /f /im notepad.exe
Terminate a process by PID:
taskkill /pid 1234
Force termination by PID:
taskkill /f /pid 1234
Start an application:
start notepad.exe
Open a directory:
start C:\Projects
Open a website:
start https://swiftener.com
Run an executable whose path contains spaces:
start "" "C:\Program Files\App\App.exe"
Windows Services
List running services:
net start
Query all services:
sc query
Query a specific service:
sc query wuauserv
Start a service:
sc start wuauserv
Stop a service:
sc stop wuauserv
Start using net:
net start wuauserv
Stop using net:
net stop wuauserv
Configure automatic startup:
sc config ServiceName start= auto
Configure manual startup:
sc config ServiceName start= demand
Disable a service:
sc config ServiceName start= disabled
The space after start= is required by the sc config syntax.
Networking Commands
Display IP configuration:
ipconfig
Display complete configuration:
ipconfig /all
Release DHCP configuration:
ipconfig /release
Renew DHCP configuration:
ipconfig /renew
Clear DNS cache:
ipconfig /flushdns
Display DNS cache:
ipconfig /displaydns
Test connectivity:
ping google.com
Ping an IP address:
ping 8.8.8.8
Continuous ping:
ping -t 8.8.8.8
Send ten packets:
ping -n 10 8.8.8.8
Trace a route:
tracert google.com
Trace without DNS lookups:
tracert -d google.com
Analyze packet loss and route:
pathping google.com
IP Configuration
Display all network adapters:
ipconfig /all
Release all DHCP addresses:
ipconfig /release
Renew all DHCP addresses:
ipconfig /renew
Flush DNS:
ipconfig /flushdns
Display DNS resolver cache:
ipconfig /displaydns
Save network information:
ipconfig /all > network.txt
Copy network information to the clipboard:
ipconfig /all | clip
DNS and Connectivity
Perform a DNS lookup:
nslookup example.com
Use a specific DNS server:
nslookup example.com 8.8.8.8
Perform a reverse lookup:
nslookup 8.8.8.8
Test a hostname:
ping example.com
Trace routing without DNS resolution:
tracert -d example.com
Use pathping for longer network diagnostics:
pathping example.com
Network Connections
Display active connections:
netstat
Display numerical addresses and ports:
netstat -an
Display process IDs:
netstat -ano
Display listening ports:
netstat -ano | findstr LISTENING
Find port 80:
netstat -ano | findstr :80
Find port 443:
netstat -ano | findstr :443
Find port 8000:
netstat -ano | findstr :8000
Identify the process using PID 1234:
tasklist /fi "PID eq 1234"
Display the ARP cache:
arp -a
Display the routing table:
route print
Display MAC addresses:
getmac
Network Shares
Display mapped network drives:
net use
Map a network drive:
net use Z: \\SERVER\Share
Map a drive with credentials:
net use Z: \\SERVER\Share /user:USERNAME
Disconnect a mapped drive:
net use Z: /delete
Remove all network connections:
net use * /delete
List shared folders:
net share
Access a network folder:
dir \\SERVER\Share
Network Reset
Reset Winsock:
netsh winsock reset
Reset TCP/IP:
netsh int ip reset
Display network interfaces:
netsh interface show interface
Display IP configuration:
netsh interface ip show config
Display Wi-Fi profiles:
netsh wlan show profiles
Display details about a Wi-Fi profile:
netsh wlan show profile name="WiFiName"
Some network reset operations require an elevated Command Prompt and may require restarting Windows.
Windows Firewall
Display firewall profiles:
netsh advfirewall show allprofiles
Display firewall rules:
netsh advfirewall firewall show rule name=all
Enable the firewall:
netsh advfirewall set allprofiles state on
Disable the firewall:
netsh advfirewall set allprofiles state off
Avoid disabling Windows Firewall unless you understand the security implications and have a specific reason to do so.
Users and Accounts
Display the current user:
whoami
Display detailed identity information:
whoami /all
List local users:
net user
Display information about a user:
net user username
Create a local user:
net user username password /add
Delete a local user:
net user username /delete
List local groups:
net localgroup
Display members of the Administrators group:
net localgroup administrators
Add a user to Administrators:
net localgroup administrators username /add
Remove a user from Administrators:
net localgroup administrators username /delete
Run a command using another account:
runas /user:Administrator cmd
Permissions and Security
Display file permissions:
icacls file.txt
Display permissions recursively:
icacls C:\MyFolder /t
Grant full control:
icacls C:\MyFolder /grant username:(F)
Grant modify permission:
icacls C:\MyFolder /grant username:(M)
Grant read and execute:
icacls C:\MyFolder /grant username:(RX)
Grant read:
icacls C:\MyFolder /grant username:(R)
Grant write:
icacls C:\MyFolder /grant username:(W)
Remove a user's permissions:
icacls C:\MyFolder /remove username
Reset permissions:
icacls C:\MyFolder /reset /t
Take ownership of a file:
takeown /f file.txt
Take ownership recursively:
takeown /f C:\MyFolder /r /d y
Common ICACLS permission codes
| Code |
Meaning |
F |
Full control |
M |
Modify |
RX |
Read and execute |
R |
Read |
W |
Write |
Disks and Storage
Check a drive:
chkdsk C:
Fix filesystem errors:
chkdsk C: /f
Check for bad sectors:
chkdsk C: /r
Display volume information:
vol C:
Display free space:
fsutil volume diskfree C:
Optimize a drive:
defrag C:
Start DiskPart:
diskpart
Basic DiskPart commands
list disk
list volume
select disk 0
detail disk
select volume 2
detail volume
exit
List physical disks:
list disk
List volumes:
list volume
Select a disk:
select disk 0
Display disk details:
detail disk
Select a volume:
select volume 2
Display volume details:
detail volume
Exit DiskPart:
exit
Dangerous DiskPart commands
clean
clean all
delete partition
format
These commands can cause permanent data loss. Always verify the selected disk or volume before modifying it.
System Information
Display Windows version:
ver
Open Windows version information:
winver
Display detailed system information:
systeminfo
Display computer name:
hostname
Display current user:
whoami
Display installed drivers:
driverquery
Save system information:
systeminfo > system-info.txt
Copy system information to the clipboard:
systeminfo | clip
System Repair
Run System File Checker:
sfc /scannow
Check the Windows component store:
DISM /Online /Cleanup-Image /CheckHealth
Scan the component store:
DISM /Online /Cleanup-Image /ScanHealth
Repair the component store:
DISM /Online /Cleanup-Image /RestoreHealth
A commonly used repair sequence is:
DISM /Online /Cleanup-Image /RestoreHealth
sfc /scannow
Check the filesystem:
chkdsk C: /f
Some repair operations require an elevated Command Prompt.
Windows Registry
Query a registry key:
reg query HKCU\Software
Query Windows startup entries:
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
Add a registry value:
reg add HKCU\Software\MyApp /v Setting /t REG_SZ /d Value
Delete a registry value:
reg delete HKCU\Software\MyApp /v Setting
Export a registry key:
reg export HKCU\Software\MyApp backup.reg
Import a registry file:
reg import backup.reg
Registry modifications can affect Windows and installed applications. Back up important registry data before making significant changes.
Scheduled Tasks
List scheduled tasks:
schtasks /query
Display detailed information:
schtasks /query /fo LIST /v
Create a daily task:
schtasks /create /sc daily /tn "Daily Backup" /tr "C:\Scripts\backup.bat" /st 22:00
Run a task:
schtasks /run /tn "Daily Backup"
End a running task:
schtasks /end /tn "Daily Backup"
Delete a task:
schtasks /delete /tn "Daily Backup"
Shutdown and Restart
Shut down immediately:
shutdown /s /t 0
Restart immediately:
shutdown /r /t 0
Log off:
shutdown /l
Schedule a shutdown:
shutdown /s /t 60
Cancel a scheduled shutdown:
shutdown /a
Restart with a message:
shutdown /r /t 60 /c "System restart scheduled"
Batch Scripting
CMD can execute batch files using either .bat or .cmd extensions.
Create a simple batch file:
@echo off
echo Hello from Windows CMD!
pause
Run the batch file:
script.bat
Run a batch file from another directory:
C:\Scripts\script.bat
Basic batch structure
@echo off
echo Starting script...
rem Commands go here
echo Script complete.
pause
Variables and Conditions
Set a variable:
set NAME=Michael
Display it:
echo %NAME%
Perform arithmetic:
set /a TOTAL=10+20
Display the result:
echo %TOTAL%
Ask the user for input:
set /p NAME=Enter your name:
Check whether a file exists:
if exist file.txt echo File exists
Check whether a file does not exist:
if not exist file.txt echo File missing
Compare strings:
if "%NAME%"=="Michael" echo Hello
Compare numbers:
if %COUNT% GEQ 10 echo Ten or more
Comparison operators
| Operator |
Meaning |
EQU |
Equal |
NEQ |
Not equal |
LSS |
Less than |
LEQ |
Less than or equal |
GTR |
Greater than |
GEQ |
Greater than or equal |
IF / ELSE
A basic conditional:
if exist file.txt (
echo File exists
) else (
echo File does not exist
)
Check a variable:
if "%STATUS%"=="OK" (
echo Everything is OK
) else (
echo An error occurred
)
Loops
Loop through files:
for %%F in (*.txt) do echo %%F
Loop recursively:
for /r %%F in (*.log) do echo %%F
Loop through directories:
for /d %%D in (*) do echo %%D
Numeric loop:
for /l %%N in (1,1,10) do echo %%N
Read a file line by line:
for /f "delims=" %%L in (file.txt) do echo %%L
Process command output:
for /f %%F in ('dir /b') do echo %%F
At the interactive CMD prompt, a for variable uses %F. Inside a batch file, it uses %%F.
Subroutines and Functions
CMD does not have functions in the same sense as modern programming languages, but batch files can use labels as subroutines.
Define a subroutine:
:hello
echo Hello!
exit /b
Call it:
call :hello
Pass an argument:
call :greet Michael
Receive the argument:
:greet
echo Hello %~1!
exit /b
A complete example:
@echo off
call :greet Michael
call :greet Sarah
exit /b
:greet
echo Hello %~1!
exit /b
String Manipulation
Display a variable:
echo %NAME%
Get the first five characters:
echo %NAME:~0,5%
Remove the first two characters:
echo %NAME:~2%
Remove the last two characters:
echo %NAME:~0,-2%
Replace text:
set TEXT=Hello World
echo %TEXT:World=CMD%
Convert a variable to uppercase or lowercase using native CMD alone is not as straightforward as in PowerShell; batch scripts commonly use substitution tables or external utilities when case conversion is required.
Delayed Variable Expansion
Normal variable expansion occurs when a command block is parsed.
Enable delayed expansion:
setlocal EnableDelayedExpansion
Use exclamation marks for delayed expansion:
!VARIABLE!
Example:
@echo off
setlocal EnableDelayedExpansion
set COUNT=0
for %%F in (*.txt) do (
set /a COUNT+=1
echo File !COUNT!: %%F
)
echo Total: !COUNT!
endlocal
This is especially useful when changing a variable inside a parenthesized block.
Command History and Console
Display command history:
doskey /history
Recall the previous command:
Up Arrow
Move forward through command history:
Down Arrow
Clear the screen:
cls
Change the command prompt:
prompt $P$G
Common prompt codes:
| Code |
Meaning |
$P |
Current drive and path |
$G |
> |
$D |
Current date |
$T |
Current time |
$N |
Current drive |
$V |
Windows version |
Set a custom prompt:
prompt $D $T $P$G
Change the CMD window title:
title My Command Prompt
Change console color:
color 0A
File Hashes
Calculate a SHA-256 hash:
certutil -hashfile file.zip SHA256
Calculate SHA-1:
certutil -hashfile file.zip SHA1
Calculate MD5:
certutil -hashfile file.zip MD5
SHA-256 is generally preferable to MD5 or SHA-1 for modern integrity verification.
Useful System Utilities
Open Task Manager:
taskmgr
Open Device Manager:
devmgmt.msc
Open Services:
services.msc
Open Disk Management:
diskmgmt.msc
Open Event Viewer:
eventvwr.msc
Open Computer Management:
compmgmt.msc
Open System Configuration:
msconfig
Open Windows Firewall:
firewall.cpl
Open Network Connections:
ncpa.cpl
Open Programs and Features:
appwiz.cpl
Open System Properties:
sysdm.cpl
CMD Shortcuts
| Shortcut |
Function |
↑ |
Previous command |
↓ |
Next command |
Tab |
Complete a file or directory name |
Ctrl+C |
Interrupt a running command |
Ctrl+V |
Paste |
Shift+Insert |
Paste |
F7 |
Display command history |
Esc |
Clear the current command |
Home |
Move to beginning of line |
End |
Move to end of line |
Ctrl+Left Arrow |
Move backward by word |
Ctrl+Right Arrow |
Move forward by word |
A-Z Command Reference
| Command |
Primary purpose |
arp |
Display or modify the ARP cache |
assoc |
Display or modify file-extension associations |
attrib |
Display or change file attributes |
bcdboot |
Set up boot files |
bcdedit |
Modify boot configuration data |
call |
Call another batch file or subroutine |
cd |
Change the current directory |
certutil |
Certificate and file-hash utilities |
chcp |
Change the active code page |
chdir |
Change the current directory |
chkdsk |
Check a disk and filesystem |
choice |
Prompt the user to select an option |
cipher |
Display or modify NTFS encryption |
cls |
Clear the CMD window |
cmd |
Start a new command interpreter |
color |
Change console colors |
comp |
Compare files |
compact |
Display or change NTFS compression |
convert |
Convert a filesystem |
copy |
Copy files |
date |
Display or set the system date |
defrag |
Defragment or optimize a drive |
del |
Delete files |
dir |
Display files and directories |
diskpart |
Manage disks and partitions |
dism |
Service Windows images |
doskey |
Command history and macros |
driverquery |
Display installed device drivers |
echo |
Display messages or control command echo |
endlocal |
End local environment changes |
erase |
Delete files |
exit |
Exit CMD |
fc |
Compare files |
find |
Search for text |
findstr |
Advanced text searching |
for |
Execute commands repeatedly |
format |
Format a disk or volume |
fsutil |
Filesystem utilities |
ftp |
Transfer files using FTP |
getmac |
Display MAC addresses |
goto |
Jump to a batch-file label |
gpupdate |
Update Group Policy |
hostname |
Display the computer name |
icacls |
Display or modify file permissions |
if |
Conditional execution |
ipconfig |
Display IP configuration |
label |
Display or change a volume label |
logoff |
Log off a user |
md |
Create a directory |
mkdir |
Create a directory |
mklink |
Create symbolic or hard links |
more |
Display output one screen at a time |
move |
Move files |
msiexec |
Windows Installer management |
net |
Network, user, and service administration |
netstat |
Display network connections |
nslookup |
Perform DNS queries |
path |
Display or modify executable search path |
pathping |
Analyze network paths |
pause |
Pause a batch script |
ping |
Test network connectivity |
popd |
Return to a saved directory |
powercfg |
Manage power settings |
prompt |
Change the CMD prompt |
pushd |
Save and change directory |
query |
Query system resources |
rd |
Remove a directory |
reg |
Manage the Windows Registry |
regsvr32 |
Register or unregister DLL components |
ren |
Rename files |
replace |
Replace files |
rmdir |
Remove a directory |
robocopy |
Robust file and directory copying |
route |
Display or modify the IP routing table |
runas |
Run a command under another account |
schtasks |
Manage scheduled tasks |
sc |
Manage Windows services |
set |
Display or modify environment variables |
setlocal |
Localize environment changes |
shutdown |
Shut down, restart, or log off |
sort |
Sort text |
start |
Start a program or command |
subst |
Associate a path with a drive letter |
systeminfo |
Display detailed system information |
takeown |
Take ownership of files |
taskkill |
Terminate processes |
tasklist |
Display running processes |
timeout |
Pause execution |
title |
Change the CMD window title |
tracert |
Trace a network route |
tree |
Display a directory tree |
type |
Display the contents of a text file |
typeperf |
Display performance counter data |
ver |
Display the Windows version |
verify |
Control verification of writes |
vol |
Display volume information |
wevtutil |
Manage Windows Event Logs |
where |
Locate executable files |
whoami |
Display current user information |
xcopy |
Copy files and directory trees |
Common Workflows
Find a program
where python
where node
where git
Check a development environment
python --version
node --version
npm --version
git --version
Find a program's location
where python
Find a process using a port
netstat -ano | findstr :8000
Then identify the process:
tasklist /fi "PID eq 1234"
Diagnose basic Internet connectivity
ipconfig /all
ping 8.8.8.8
nslookup google.com
ping google.com
tracert google.com
Flush DNS
ipconfig /flushdns
Reset common Windows networking components
ipconfig /flushdns
netsh winsock reset
netsh int ip reset
Restart Windows if required:
shutdown /r /t 0
Diagnose Windows system-file problems
DISM /Online /Cleanup-Image /RestoreHealth
sfc /scannow
Save system diagnostics
systeminfo > system.txt
ipconfig /all > network.txt
tasklist > processes.txt
netstat -ano > connections.txt
Search an entire project for a word
findstr /s /i "database" *.py *.js *.php *.html
List every file in a project
dir /s /b > files.txt
Copy a project to a backup directory
robocopy C:\Projects\MyApp D:\Backup\MyApp /E
Count files in a directory
dir /b /a-d | find /c /v ""
Find all log files
dir /s /b *.log
Find errors in log files
findstr /s /i "error failed exception warning" *.log
Find a running application
tasklist | findstr /i chrome
Stop an application
taskkill /im chrome.exe /f
Batch Automation Example
The following example creates a simple backup script:
@echo off
set SOURCE=C:\Projects
set DESTINATION=D:\Backup\Projects
echo Starting backup...
echo Source: %SOURCE%
echo Destination: %DESTINATION%
robocopy "%SOURCE%" "%DESTINATION%" /E
if %ERRORLEVEL% LEQ 7 (
echo Backup completed.
) else (
echo Backup encountered an error.
)
pause
The ERRORLEVEL returned by robocopy has its own documented status-code conventions, so a nonzero value does not necessarily mean that the operation failed.
Useful One-Liners
Display the current directory:
echo %CD%
Display the current username:
echo %USERNAME%
Display the computer name:
echo %COMPUTERNAME%
Display the Windows directory:
echo %SystemRoot%
Display the PATH:
echo %PATH%
Find Python:
where python
Find Node.js:
where node
Find Git:
where git
Find Chrome processes:
tasklist | findstr /i chrome
Find listening ports:
netstat -ano | findstr LISTENING
Find a specific port:
netstat -ano | findstr :8000
Copy command output:
command | clip
Save command output:
command > output.txt
Append command output:
command >> output.txt
Clear the screen:
cls
Safety Checklist
Before executing a potentially destructive command, verify:
✓ Correct drive
✓ Correct directory
✓ Correct filename
✓ Correct user
✓ Correct disk
✓ Correct destination
✓ Correct permissions
✓ Backup available
Pay particular attention to:
del
rmdir /s
format
diskpart
reg delete
bcdedit
bcdboot
icacls
takeown
netsh
sc
robocopy /MIR
For example:
rmdir /s /q C:\Folder
can permanently remove the specified directory and its contents.
Likewise:
robocopy C:\Source C:\Destination /MIR
can delete destination files that are absent from the source.
DiskPart deserves particular caution:
diskpart
list disk
select disk 0
clean
The clean command can remove partition information from the selected disk.
Always confirm the selected disk before executing destructive DiskPart commands.
CMD vs PowerShell
CMD and PowerShell are separate Windows command-line environments.
CMD is commonly used for:
- Traditional Windows commands
- Batch scripts
- Simple file operations
- Basic network diagnostics
- Legacy automation
- Compatibility with older command-line tools
PowerShell provides additional capabilities for:
- Structured data
- Advanced automation
- Object-based pipelines
- Windows administration
- Remote administration
- Complex scripting
CMD remains useful even on modern Windows systems because many Windows utilities, installers, scripts, and administrative procedures continue to support it.
Tips & Tricks
Use Tab completion
Instead of typing a complete path:
cd C:\Users\Michael\Documents
type part of the path and press:
Tab
CMD can complete matching files and directories.
Save command output
ipconfig /all > network.txt
Append output
ipconfig /all >> network.txt
Copy output to the clipboard
systeminfo | clip
Combine commands
cd C:\Projects && dir
Search command output
tasklist | findstr /i python
Suppress unwanted output
command > nul 2>&1
Get help whenever you are unsure
command /?
Essential CMD Pocket Reference
Navigation
cd
cd ..
cd \
cd /d D:\Folder
pushd C:\Folder
popd
dir
tree /f
Files
copy
move
ren
del
type
attrib
Directories
mkdir
md
rmdir
rd
Search
where
find
findstr
Processes
tasklist
taskkill
start
Services
sc query
sc start
sc stop
net start
net stop
Networking
ipconfig
ping
tracert
pathping
nslookup
netstat
arp
route
getmac
System
systeminfo
hostname
ver
whoami
driverquery
Repair
chkdsk
sfc
DISM
Storage
diskpart
fsutil
defrag
vol
Administration
net user
net localgroup
icacls
takeown
reg
schtasks
Batch scripting
echo
set
if
for
call
goto
pause
exit
Conclusion
Microsoft Command Prompt remains one of the most useful command-line environments available on Windows.
The commands in this cheat sheet cover the major areas of everyday CMD usage:
File management
Directory navigation
Text processing
Searching
Environment variables
Command pipelines
Output redirection
Process management
Windows services
Networking
DNS
Firewall configuration
User accounts
Permissions
Disk management
System information
System repair
Registry management
Scheduled tasks
Shutdown and restart
Batch scripting
Automation
The most useful commands to learn first are:
cd
dir
copy
move
del
mkdir
rmdir
ren
type
findstr
where
ipconfig
ping
tracert
nslookup
netstat
tasklist
taskkill
systeminfo
whoami
robocopy
icacls
chkdsk
sfc
DISM
set
if
for
When you encounter an unfamiliar command, use:
command /?
For example:
robocopy /?
The built-in help is one of the fastest ways to discover a command's syntax and available options.
Last reviewed: September 2026