CMD commands
Windows Command Prompt shell interpreter
Navigation & File System
cdPrint the current working directory path
cd <directory>Change the current working directory
cd ..Move up one level to the parent directory
cd \Navigate to the root of the current drive
cd /d <drive>:\<path>Change both the drive and directory at the same time
<drive>:Switch to a different drive (e.g., D:)
dirList all files and folders in the current directory
dir /aList all files including hidden and system files
dir /a:hList only hidden files
dir /a:dList only directories
dir /sList all files in the directory and all subdirectories
dir /bDisplay only file and folder names in bare format
dir /o:nList files sorted alphabetically by name
dir /o:sList files sorted by size
dir /o:dList files sorted by date
dir /o:-dList files sorted by date in reverse order
dir /pList files one page at a time
dir /wList files in wide format using multiple columns
dir <pattern>List files matching a specific pattern (e.g., dir *.txt)
dir /s /b <pattern>Recursively search and list files matching a pattern
pushd <path>Save the current directory and navigate to a new path
popdReturn to the directory saved by pushd
treeDisplay the directory structure as an ASCII tree
tree /fDisplay the directory tree including file names
tree /aDisplay the tree using ASCII characters instead of graphic ones
File & Directory Operations
mkdir <directory>Create a new directory
md <directory>Alias for mkdir, creates a new directory
mkdir <path\subpath>Create a directory and all required parent directories
rmdir <directory>Remove an empty directory
rd <directory>Alias for rmdir, removes an empty directory
rmdir /s <directory>Recursively delete a directory and all its contents
rmdir /s /q <directory>Quietly delete a directory and all its contents without prompting
del <file>Delete a file
del /f <file>Forcefully delete a read-only file
del /q <file>Delete a file without asking for confirmation
del /s <pattern>Delete matching files in all subdirectories
del /f /q /s <pattern>Force-delete files recursively without prompting
erase <file>Alias for del, deletes a file
copy <source> <destination>Copy a file to a destination
copy /y <source> <destination>Copy a file without prompting to confirm overwrite
copy /b <source> <destination>Copy a file in binary mode
copy <file1>+<file2> <destination>Concatenate multiple files into one destination file
xcopy <source> <destination>Copy files and directory trees
xcopy <source> <destination> /eCopy all subdirectories including empty ones
xcopy <source> <destination> /sCopy subdirectories excluding empty directories
xcopy <source> <destination> /hCopy hidden and system files
xcopy <source> <destination> /yCopy without prompting to overwrite destination files
xcopy <source> <destination> /qCopy quietly without displaying file names
xcopy <source> <destination> /iAssume destination is a directory if it does not exist
xcopy <source> <destination> /exclude:<file>Copy excluding files listed in an exclusion file
robocopy <source> <destination>Robust file copy for Windows with advanced options
robocopy <source> <destination> /eCopy all subdirectories including empty ones
robocopy <source> <destination> /sCopy all subdirectories excluding empty ones
robocopy <source> <destination> /mirMirror the source to destination, deleting extra files
robocopy <source> <destination> /moveMove files and directories, deleting them from source
robocopy <source> <destination> /zCopy in restartable mode for interrupted transfers
robocopy <source> <destination> /xf <file>Exclude specific files during robocopy
robocopy <source> <destination> /xd <dir>Exclude specific directories during robocopy
robocopy <source> <destination> /log:<file>Write robocopy output to a log file
move <source> <destination>Move or rename a file or directory
move /y <source> <destination>Move a file without prompting to overwrite
ren <oldname> <newname>Rename a file or directory
rename <oldname> <newname>Alias for ren, renames a file or directory
type nul > <file>Create a new empty file
echo. > <file>Create a new file with a single blank line
mklink <link> <target>Create a symbolic link to a file
mklink /d <link> <target>Create a symbolic link to a directory
mklink /h <link> <target>Create a hard link to a file
mklink /j <link> <target>Create a directory junction (soft link for directories)
attrib <file>Display the attributes of a file
attrib +h <file>Set a file as hidden
attrib -h <file>Remove the hidden attribute from a file
attrib +r <file>Set a file as read-only
attrib -r <file>Remove the read-only attribute from a file
attrib +s <file>Set the system attribute on a file
attrib /s /d <pattern>Apply attribute changes recursively to subdirectories
compact /c <file>Compress a file using NTFS compression
compact /u <file>Uncompress a file using NTFS compression
File Viewing & Content
type <file>Display the contents of a text file
type <file> | moreDisplay file contents one page at a time
more <file>Display file contents one screen at a time
more /e <file>Display file contents with extended features enabled
find "<string>" <file>Search for a specific string in a file
find /i "<string>" <file>Search for a string case-insensitively
find /n "<string>" <file>Search for a string and show matching line numbers
find /v "<string>" <file>Print lines that do NOT contain the string
find /c "<string>" <file>Count the number of lines containing the string
findstr <pattern> <file>Search for a pattern or string in a file
findstr /i <pattern> <file>Search for a pattern case-insensitively
findstr /r <pattern> <file>Search using a regular expression pattern
findstr /s <pattern> <path>Recursively search files in the current and subdirectories
findstr /n <pattern> <file>Show the line numbers of matching lines
findstr /v <pattern> <file>Print lines that do NOT match the pattern
findstr /l <string> <file>Search for a literal string instead of a regex
findstr /c:"<string>" <file>Search for an exact literal string with spaces
findstr /m <pattern> <files>Print only the names of files containing matches
comp <file1> <file2>Compare the contents of two files
fc <file1> <file2>Compare two files and display the differences
fc /b <file1> <file2>Compare two files in binary mode
fc /i <file1> <file2>Compare two files ignoring case differences
fc /n <file1> <file2>Compare text files and display line numbers with differences
System Information
systeminfoDisplay detailed Windows configuration information
systeminfo | findstr /b /c:"OS"Display only OS information from systeminfo
verDisplay the current Windows version
hostnameDisplay the name of the current computer
whoamiDisplay the current domain and username
whoami /allDisplay current user, groups, and privileges
whoami /groupsDisplay the groups the current user belongs to
whoami /privDisplay the privileges of the current user
dateDisplay or set the current date
date /tDisplay the current date without prompting to change it
timeDisplay or set the current time
time /tDisplay the current time without prompting to change it
setDisplay all environment variables in the current session
set <variable>Display the value of a specific environment variable
set <variable>=<value>Set an environment variable for the current session
setx <variable> <value>Permanently set an environment variable for the user
setx <variable> <value> /mPermanently set an environment variable system-wide
echo %<variable>%Display the value of an environment variable
echo %USERNAME%Display the current logged-in username
echo %COMPUTERNAME%Display the computer name
echo %OS%Display the operating system name
echo %PROCESSOR_ARCHITECTURE%Display the processor architecture
echo %USERPROFILE%Display the path to the current user's profile directory
echo %TEMP%Display the path to the temporary files directory
echo %PATH%Display the current system PATH
wmic os get captionDisplay the operating system name via WMI
wmic os get versionDisplay the operating system version via WMI
wmic cpu get nameDisplay the CPU name via WMI
wmic memorychip get capacityDisplay the RAM capacity of each module via WMI
wmic diskdrive get model,sizeDisplay disk drive models and sizes via WMI
wmic bios get serialnumberDisplay the system BIOS serial number via WMI
wmic product get nameList all installed software products via WMI
wmic process list briefList all running processes with basic info via WMI
wmic service list briefList all Windows services with brief info via WMI
msinfo32Open the System Information graphical tool
Process Management
tasklistList all currently running processes
tasklist /fi "IMAGENAME eq <name>"Filter processes by executable name
tasklist /fi "STATUS eq running"List only processes with a running status
tasklist /fi "PID eq <pid>"List a specific process by its PID
tasklist /svcList processes along with their hosted services
tasklist /vList processes with verbose details
tasklist /mList processes along with DLLs they have loaded
tasklist /fo csvList processes in CSV output format
tasklist /fo tableList processes in formatted table output
taskkill /im <name>Terminate a process by its executable name
taskkill /pid <pid>Terminate a process by its PID
taskkill /im <name> /fForcefully terminate a process by name
taskkill /pid <pid> /fForcefully terminate a process by PID
taskkill /im <name> /tTerminate a process and all its child processes
taskkill /f /im <name> /tForcefully terminate a process tree
start <program>Start a new program or command in a new window
start "<title>" <program>Start a program in a new window with a custom title
start /wait <program>Start a program and wait for it to finish
start /min <program>Start a program in a minimized window
start /max <program>Start a program in a maximized window
start /b <program>Start a program in the background without a new window
timeout /t <seconds>Pause execution for a specified number of seconds
timeout /t <seconds> /nobreakPause without allowing keyboard interruption
ping -n 1 127.0.0.1 > nul && <command>Delay a command by using a ping as a timer
Network
ping <host>Send ICMP echo requests to test connectivity to a host
ping <host> -n <count>Send a specified number of ping packets to a host
ping <host> -tPing a host continuously until stopped manually
ping <host> -l <size>Ping with a specified packet size
ping <host> -4Force ping to use IPv4
ping <host> -6Force ping to use IPv6
ping <host> -aResolve the hostname from an IP address when pinging
ipconfigDisplay IP configuration for all network adapters
ipconfig /allDisplay full IP configuration details for all adapters
ipconfig /releaseRelease the DHCP IP address for all adapters
ipconfig /renewRenew the DHCP IP address for all adapters
ipconfig /flushdnsFlush and reset the DNS resolver cache
ipconfig /displaydnsDisplay the contents of the DNS resolver cache
ipconfig /registerdnsRefresh DHCP leases and re-register DNS names
nslookup <domain>Query DNS to find the IP address of a domain
nslookup <domain> <dns-server>Query a specific DNS server for a domain
nslookup -type=<type> <domain>Query a specific DNS record type
tracert <host>Trace the network route packets take to a host
tracert -d <host>Trace route without resolving hostnames
tracert -h <hops> <host>Trace route with a maximum number of hops
pathping <host>Trace a route and measure packet loss at each hop
netstatDisplay active network connections and listening ports
netstat -aDisplay all active connections and listening ports
netstat -nDisplay connections with numeric IP addresses and ports
netstat -anDisplay all connections with numeric addresses
netstat -bDisplay the executable involved in each connection
netstat -oDisplay process IDs associated with each connection
netstat -anoDisplay all connections with addresses and PIDs numerically
netstat -rDisplay the routing table
netstat -eDisplay Ethernet statistics
netstat -sDisplay per-protocol statistics
netstat -p <protocol>Display connections for a specific protocol
net viewDisplay a list of computers in the current network
net view \\<computer>List shared resources on a specific computer
net useList all current network connections and mapped drives
net use <drive>: \\<host>\<share>Map a network share to a drive letter
net use <drive>: /deleteDisconnect a mapped network drive
net shareDisplay all shared resources on the local computer
net share <name>=<path>Create a new network share
net share <name> /deleteDelete an existing network share
arp -aDisplay the ARP cache showing IP-to-MAC mappings
arp -d <ip>Delete a specific entry from the ARP cache
arp -s <ip> <mac>Add a static ARP entry
route printDisplay the full routing table
route add <destination> mask <mask> <gateway>Add a new route to the routing table
route delete <destination>Delete a route from the routing table
netsh wlan show profilesList all saved Wi-Fi profiles
netsh wlan show profile name="<ssid>" key=clearDisplay a Wi-Fi profile including the saved password
netsh wlan connect name="<ssid>"Connect to a saved Wi-Fi network
netsh wlan disconnectDisconnect from the current Wi-Fi network
netsh interface ip set address <adapter> static <ip> <mask> <gateway>Set a static IP address on a network adapter
netsh interface ip set address <adapter> dhcpSet a network adapter to use DHCP
netsh advfirewall set allprofiles state onEnable Windows Firewall for all profiles
netsh advfirewall set allprofiles state offDisable Windows Firewall for all profiles
netsh advfirewall firewall add rule name="<n>" protocol=TCP dir=in localport=<port> action=allowAdd a firewall rule to allow inbound TCP traffic on a port
netsh advfirewall firewall delete rule name="<n>"Delete a specific firewall rule by name
ftp <host>Open an FTP connection to a remote host
curl <url>Transfer data from a URL (available in Windows 10+)
curl -o <file> <url>Download a URL and save it to a file
User & Account Management
net userList all local user accounts
net user <username>Display detailed information about a specific user account
net user <username> <password> /addCreate a new local user account with a password
net user <username> /deleteDelete a local user account
net user <username> <password>Change the password for a local user account
net user <username> /active:yesEnable a disabled user account
net user <username> /active:noDisable a user account
net user <username> /passwordreq:yesRequire a password for a user account
net user <username> /expires:<date>Set an expiration date for a user account
net localgroupList all local groups
net localgroup <group>Display members of a specific local group
net localgroup <group> <user> /addAdd a user to a local group
net localgroup <group> <user> /deleteRemove a user from a local group
net localgroup <group> /addCreate a new local group
net localgroup <group> /deleteDelete a local group
runas /user:<domain>\<user> <command>Run a command as a different user
runas /user:Administrator <command>Run a command as the Administrator user
net accountsDisplay password and logon policy for the local computer
net accounts /maxpwage:<days>Set the maximum password age in days
net accounts /minpwlen:<length>Set the minimum password length
Services Management
sc queryList the status of all services
sc query <service>Display the status of a specific service
sc query type= allList all services and drivers
sc query state= allList all services regardless of their state
sc start <service>Start a service
sc stop <service>Stop a running service
sc pause <service>Pause a running service
sc continue <service>Resume a paused service
sc config <service> start= autoSet a service to start automatically
sc config <service> start= demandSet a service to start manually
sc config <service> start= disabledDisable a service from starting
sc create <service> binPath= "<path>"Create a new service with a binary path
sc delete <service>Mark a service for deletion
sc description <service> "<desc>"Set a description for a service
net startList all currently running services
net start <service>Start a Windows service by name
net stop <service>Stop a Windows service by name
net pause <service>Pause a running service
net continue <service>Continue a paused service
Disk & Storage
diskpartOpen the interactive disk partitioning tool
chkdskCheck the current drive for errors
chkdsk <drive>:Check a specific drive for file system errors
chkdsk <drive>: /fCheck and fix file system errors on a drive
chkdsk <drive>: /rLocate bad sectors and recover readable data
chkdsk <drive>: /xForce dismount before checking (use with /f)
format <drive>:Format a disk drive
format <drive>: /fs:NTFSFormat a drive with the NTFS file system
format <drive>: /fs:FAT32Format a drive with the FAT32 file system
format <drive>: /qQuick format a drive
label <drive>: <name>Set or change the volume label of a drive
vol <drive>:Display the volume label and serial number of a drive
fsutil volume diskfree <drive>:Display free and total disk space for a drive
fsutil file createnew <file> <size>Create a new file of a specified size in bytes
subst <drive>: <path>Assign a drive letter to a folder path
subst <drive>: /dRemove a substituted drive letter
substList all current drive substitutions
defrag <drive>: /u /vDefragment a drive with progress reporting
defrag <drive>: /aAnalyze a drive without defragmenting
Batch Scripting
@echo offTurn off command echoing for the rest of the script
echo <message>Print a message to the console
echo.Print a blank line to the console
echo %<variable>%Print the value of a variable
set <variable>=<value>Set a variable in the current batch session
set /p <variable>=<prompt>Prompt the user to input a value for a variable
set /a <variable>=<expression>Evaluate an arithmetic expression and store the result
if <condition> <command>Execute a command if a condition is true
if exist <file> <command>Execute a command if a file exists
if not exist <file> <command>Execute a command if a file does not exist
if %<variable>%==<value> <command>Execute a command if a variable equals a value
if /i %<variable>%==<value> <command>Case-insensitive comparison of a variable to a value
if %errorlevel%==0 <command>Execute a command if the previous command succeeded
if defined <variable> <command>Execute a command if a variable is defined
if not defined <variable> <command>Execute a command if a variable is not defined
if <n1> gtr <n2> <command>Execute a command if n1 is greater than n2
if <n1> lss <n2> <command>Execute a command if n1 is less than n2
if <n1> equ <n2> <command>Execute a command if n1 equals n2
if <n1> neq <n2> <command>Execute a command if n1 does not equal n2
for %i in (<set>) do <command>Loop through a set of values
for /l %i in (<start>,<step>,<end>) do <command>Numeric for loop from start to end with step increment
for /f %i in (<file>) do <command>Loop through each line of a file
for /f "tokens=*" %i in ('<command>') do <cmd>Loop through the output of a command
for /r <path> %i in (<pattern>) do <command>Recursively loop through files matching a pattern
for /d %i in (<pattern>) do <command>Loop through matching directories only
goto <label>Jump script execution to a labelled section
:<label>Define a label to jump to with goto
call <script>.batCall and run another batch script
call :<subroutine>Call a subroutine defined in the same batch file
exit /b <code>Exit the current batch script with an exit code
exit <code>Exit the command prompt session with an exit code
%~1Get the first argument passed to the script, removing quotes
%~dp0Get the drive and path of the batch file itself
%~f1Get the fully qualified path of the first argument
%~n1Get the filename without extension from the first argument
%~x1Get the file extension from the first argument
pausePause execution and wait for the user to press a key
choice /c <chars> /m <message>Prompt the user to press one of a set of characters
setlocalBegin local environment changes in a script
endlocalEnd local environment changes and restore original environment
setlocal enabledelayedexpansionEnable delayed variable expansion using !variable! syntax
enableextensionsEnable command extensions for enhanced batch features
rem <comment>Add a comment to a batch script (not executed)
:: <comment>Add a comment using the double-colon syntax
Redirection & Pipelines
<command> > <file>Redirect command output to a file, overwriting it
<command> >> <file>Redirect command output and append it to a file
<command> < <file>Use a file as standard input for a command
<command> 2> <file>Redirect error output to a file
<command> 2>> <file>Append error output to a file
<command> 2>&1Redirect stderr to the same destination as stdout
<command> > <file> 2>&1Redirect both stdout and stderr to a file
<command> > nulDiscard standard output
<command> > nul 2>&1Discard both standard output and error output
<command1> | <command2>Pipe the output of command1 as input to command2
<command1> && <command2>Run command2 only if command1 succeeds
<command1> || <command2>Run command2 only if command1 fails
<command1> & <command2>Run command1 then command2 unconditionally
<command> | clipPipe the output of a command to the clipboard
<command> | morePipe output through the more pager
<command> | find "<string>"Pipe output and filter for a specific string
<command> | findstr "<pattern>"Pipe output and filter using a pattern or regex
<command> | sortPipe output and sort it alphabetically
<command> | sort /rPipe output and sort it in reverse order
System Administration
shutdown /sShut down the local computer
shutdown /s /t <seconds>Shut down the computer after a specified delay
shutdown /rRestart the local computer
shutdown /hHibernate the local computer
shutdown /lLog off the current user
shutdown /aAbort a pending shutdown
shutdown /m \\<computer> /sRemotely shut down another computer
shutdown /r /oRestart into the Advanced Boot Options menu
gpupdateRefresh Group Policy settings
gpupdate /forceForce a full refresh of all Group Policy settings
gpresult /rDisplay the Resultant Set of Policy for the current user
gpresult /h <file>.htmlGenerate an HTML Group Policy report
sfc /scannowScan and repair protected Windows system files
sfc /verifyonlyScan system files for integrity without repairing
dism /online /cleanup-image /restorehealthScan and repair the Windows image using DISM
dism /online /cleanup-image /scanhealthScan the Windows image for corruption
dism /online /cleanup-image /checkhealthCheck if the Windows image is flagged as corrupted
reg query <key>Query and display registry key values
reg query <key> /v <valuename>Query a specific registry value
reg add <key> /v <name> /t <type> /d <data>Add or update a registry value
reg delete <key> /v <valuename>Delete a specific registry value
reg delete <key>Delete a registry key and all its values
reg export <key> <file>.regExport a registry key to a .reg file
reg import <file>.regImport a .reg file into the registry
reg copy <source> <destination>Copy a registry key and all its subkeys to another location
regeditOpen the graphical Registry Editor
msconfigOpen the System Configuration tool
eventvwrOpen the Event Viewer
devmgmt.mscOpen the Device Manager
services.mscOpen the Services management console
compmgmt.mscOpen the Computer Management console
diskmgmt.mscOpen the Disk Management console
taskschd.mscOpen the Task Scheduler
controlOpen the Control Panel
control <applet>Open a specific Control Panel applet
wuauclt /detectnowForce Windows Update to check for updates immediately
bcdeditDisplay and manage the boot configuration data
bcdedit /enumList all boot entries in the boot configuration
Miscellaneous
clsClear the command prompt screen
helpDisplay a list of built-in CMD commands with brief descriptions
help <command>Display help documentation for a specific command
<command> /?Display help and usage information for any command
color <attr>Change the foreground and background colors of the console
color 0aSet black background with green text
title <text>Set the title of the current command prompt window
prompt <text>Change the command prompt text
prompt $P$GReset the prompt to show current directory and >
mode con cols=<n> lines=<n>Set the console window size in columns and lines
doskey <alias>=<command>Create a command alias (macro) in CMD
doskey /historyDisplay the command history for the current session
doskey /macrosList all currently defined macros
clipCopy stdin or piped output to the Windows clipboard
sortSort the lines of input alphabetically
sort /rSort the lines of input in reverse order
sort /+<n>Sort starting from character position <n>
assocDisplay all file extension associations
assoc .<ext>Display the file type associated with an extension
assoc .<ext>=<filetype>Associate a file extension with a file type
ftypeDisplay all file type open commands
ftype <filetype>Display the open command for a specific file type
ftype <filetype>=<command>Set the open command for a file type
where <command>Find the location of an executable in the PATH
certutil -hashfile <file> MD5Compute the MD5 hash of a file
certutil -hashfile <file> SHA256Compute the SHA256 hash of a file
certutil -encode <infile> <outfile>Base64-encode a file
certutil -decode <infile> <outfile>Base64-decode a file
cipher /e <file>Encrypt a file using NTFS EFS encryption
cipher /d <file>Decrypt an EFS-encrypted file
cipher /w:<path>Securely wipe free space on a drive
fc /b <file1> <file2>Compare two files byte by byte
powercfg /batteryreportGenerate a detailed battery usage report
powercfg /energyAnalyze power usage and generate an energy report
powercfg /listList all available power plans
powercfg /setactive <scheme>Set the active power plan