CMD
CMD

File & Directory Operations

Create a new directory

$mkdir <directory>

Alias for mkdir, creates a new directory

$md <directory>

Create a directory and all required parent directories

$mkdir <path\subpath>

Remove an empty directory

$rmdir <directory>

Alias for rmdir, removes an empty directory

$rd <directory>

Recursively delete a directory and all its contents

$rmdir /s <directory>

Quietly delete a directory and all its contents without prompting

$rmdir /s /q <directory>

Delete a file

$del <file>

Forcefully delete a read-only file

$del /f <file>

Delete a file without asking for confirmation

$del /q <file>

Delete matching files in all subdirectories

$del /s <pattern>

Force-delete files recursively without prompting

$del /f /q /s <pattern>

Alias for del, deletes a file

$erase <file>

Copy a file to a destination

$copy <source> <destination>

Copy a file without prompting to confirm overwrite

$copy /y <source> <destination>

Copy a file in binary mode

$copy /b <source> <destination>

Concatenate multiple files into one destination file

$copy <file1>+<file2> <destination>

Copy files and directory trees

$xcopy <source> <destination>

Copy all subdirectories including empty ones

$xcopy <source> <destination> /e

Copy subdirectories excluding empty directories

$xcopy <source> <destination> /s

Copy hidden and system files

$xcopy <source> <destination> /h

Copy without prompting to overwrite destination files

$xcopy <source> <destination> /y

Copy quietly without displaying file names

$xcopy <source> <destination> /q

Assume destination is a directory if it does not exist

$xcopy <source> <destination> /i

Copy excluding files listed in an exclusion file

$xcopy <source> <destination> /exclude:<file>

Robust file copy for Windows with advanced options

$robocopy <source> <destination>

Copy all subdirectories including empty ones

$robocopy <source> <destination> /e

Copy all subdirectories excluding empty ones

$robocopy <source> <destination> /s

Mirror the source to destination, deleting extra files

$robocopy <source> <destination> /mir

Move files and directories, deleting them from source

$robocopy <source> <destination> /move

Copy in restartable mode for interrupted transfers

$robocopy <source> <destination> /z

Exclude specific files during robocopy

$robocopy <source> <destination> /xf <file>

Exclude specific directories during robocopy

$robocopy <source> <destination> /xd <dir>

Write robocopy output to a log file

$robocopy <source> <destination> /log:<file>

Move or rename a file or directory

$move <source> <destination>

Move a file without prompting to overwrite

$move /y <source> <destination>

Rename a file or directory

$ren <oldname> <newname>

Alias for ren, renames a file or directory

$rename <oldname> <newname>

Create a new empty file

$type nul > <file>

Create a new file with a single blank line

$echo. > <file>

Create a symbolic link to a file

$mklink <link> <target>

Create a symbolic link to a directory

$mklink /d <link> <target>

Create a hard link to a file

$mklink /h <link> <target>

Create a directory junction (soft link for directories)

$mklink /j <link> <target>

Display the attributes of a file

$attrib <file>

Set a file as hidden

$attrib +h <file>

Remove the hidden attribute from a file

$attrib -h <file>

Set a file as read-only

$attrib +r <file>

Remove the read-only attribute from a file

$attrib -r <file>

Set the system attribute on a file

$attrib +s <file>

Apply attribute changes recursively to subdirectories

$attrib /s /d <pattern>

Compress a file using NTFS compression

$compact /c <file>

Uncompress a file using NTFS compression

$compact /u <file>

File Viewing & Content

Display the contents of a text file

$type <file>

Display file contents one page at a time

$type <file> | more

Display file contents one screen at a time

$more <file>

Display file contents with extended features enabled

$more /e <file>

Search for a specific string in a file

$find "<string>" <file>

Search for a string case-insensitively

$find /i "<string>" <file>

Search for a string and show matching line numbers

$find /n "<string>" <file>

Print lines that do NOT contain the string

$find /v "<string>" <file>

Count the number of lines containing the string

$find /c "<string>" <file>

Search for a pattern or string in a file

$findstr <pattern> <file>

Search for a pattern case-insensitively

$findstr /i <pattern> <file>

Search using a regular expression pattern

$findstr /r <pattern> <file>

Recursively search files in the current and subdirectories

$findstr /s <pattern> <path>

Show the line numbers of matching lines

$findstr /n <pattern> <file>

Print lines that do NOT match the pattern

$findstr /v <pattern> <file>

Search for a literal string instead of a regex

$findstr /l <string> <file>

Search for an exact literal string with spaces

$findstr /c:"<string>" <file>

Print only the names of files containing matches

$findstr /m <pattern> <files>

Compare the contents of two files

$comp <file1> <file2>

Compare two files and display the differences

$fc <file1> <file2>

Compare two files in binary mode

$fc /b <file1> <file2>

Compare two files ignoring case differences

$fc /i <file1> <file2>

Compare text files and display line numbers with differences

$fc /n <file1> <file2>

System Information

Display detailed Windows configuration information

$systeminfo

Display only OS information from systeminfo

$systeminfo | findstr /b /c:"OS"

Display the current Windows version

$ver

Display the name of the current computer

$hostname

Display the current domain and username

$whoami

Display current user, groups, and privileges

$whoami /all

Display the groups the current user belongs to

$whoami /groups

Display the privileges of the current user

$whoami /priv

Display or set the current date

$date

Display the current date without prompting to change it

$date /t

Display or set the current time

$time

Display the current time without prompting to change it

$time /t

Display all environment variables in the current session

$set

Display the value of a specific environment variable

$set <variable>

Set an environment variable for the current session

$set <variable>=<value>

Permanently set an environment variable for the user

$setx <variable> <value>

Permanently set an environment variable system-wide

$setx <variable> <value> /m

Display the value of an environment variable

$echo %<variable>%

Display the current logged-in username

$echo %USERNAME%

Display the computer name

$echo %COMPUTERNAME%

Display the operating system name

$echo %OS%

Display the processor architecture

$echo %PROCESSOR_ARCHITECTURE%

Display the path to the current user's profile directory

$echo %USERPROFILE%

Display the path to the temporary files directory

$echo %TEMP%

Display the current system PATH

$echo %PATH%

Display the operating system name via WMI

$wmic os get caption

Display the operating system version via WMI

$wmic os get version

Display the CPU name via WMI

$wmic cpu get name

Display the RAM capacity of each module via WMI

$wmic memorychip get capacity

Display disk drive models and sizes via WMI

$wmic diskdrive get model,size

Display the system BIOS serial number via WMI

$wmic bios get serialnumber

List all installed software products via WMI

$wmic product get name

List all running processes with basic info via WMI

$wmic process list brief

List all Windows services with brief info via WMI

$wmic service list brief

Open the System Information graphical tool

$msinfo32

Process Management

List all currently running processes

$tasklist

Filter processes by executable name

$tasklist /fi "IMAGENAME eq <name>"

List only processes with a running status

$tasklist /fi "STATUS eq running"

List a specific process by its PID

$tasklist /fi "PID eq <pid>"

List processes along with their hosted services

$tasklist /svc

List processes with verbose details

$tasklist /v

List processes along with DLLs they have loaded

$tasklist /m

List processes in CSV output format

$tasklist /fo csv

List processes in formatted table output

$tasklist /fo table

Terminate a process by its executable name

$taskkill /im <name>

Terminate a process by its PID

$taskkill /pid <pid>

Forcefully terminate a process by name

$taskkill /im <name> /f

Forcefully terminate a process by PID

$taskkill /pid <pid> /f

Terminate a process and all its child processes

$taskkill /im <name> /t

Forcefully terminate a process tree

$taskkill /f /im <name> /t

Start a new program or command in a new window

$start <program>

Start a program in a new window with a custom title

$start "<title>" <program>

Start a program and wait for it to finish

$start /wait <program>

Start a program in a minimized window

$start /min <program>

Start a program in a maximized window

$start /max <program>

Start a program in the background without a new window

$start /b <program>

Pause execution for a specified number of seconds

$timeout /t <seconds>

Pause without allowing keyboard interruption

$timeout /t <seconds> /nobreak

Delay a command by using a ping as a timer

$ping -n 1 127.0.0.1 > nul && <command>

Network

Send ICMP echo requests to test connectivity to a host

$ping <host>

Send a specified number of ping packets to a host

$ping <host> -n <count>

Ping a host continuously until stopped manually

$ping <host> -t

Ping with a specified packet size

$ping <host> -l <size>

Force ping to use IPv4

$ping <host> -4

Force ping to use IPv6

$ping <host> -6

Resolve the hostname from an IP address when pinging

$ping <host> -a

Display IP configuration for all network adapters

$ipconfig

Display full IP configuration details for all adapters

$ipconfig /all

Release the DHCP IP address for all adapters

$ipconfig /release

Renew the DHCP IP address for all adapters

$ipconfig /renew

Flush and reset the DNS resolver cache

$ipconfig /flushdns

Display the contents of the DNS resolver cache

$ipconfig /displaydns

Refresh DHCP leases and re-register DNS names

$ipconfig /registerdns

Query DNS to find the IP address of a domain

$nslookup <domain>

Query a specific DNS server for a domain

$nslookup <domain> <dns-server>

Query a specific DNS record type

$nslookup -type=<type> <domain>

Trace the network route packets take to a host

$tracert <host>

Trace route without resolving hostnames

$tracert -d <host>

Trace route with a maximum number of hops

$tracert -h <hops> <host>

Trace a route and measure packet loss at each hop

$pathping <host>

Display active network connections and listening ports

$netstat

Display all active connections and listening ports

$netstat -a

Display connections with numeric IP addresses and ports

$netstat -n

Display all connections with numeric addresses

$netstat -an

Display the executable involved in each connection

$netstat -b

Display process IDs associated with each connection

$netstat -o

Display all connections with addresses and PIDs numerically

$netstat -ano

Display the routing table

$netstat -r

Display Ethernet statistics

$netstat -e

Display per-protocol statistics

$netstat -s

Display connections for a specific protocol

$netstat -p <protocol>

Display a list of computers in the current network

$net view

List shared resources on a specific computer

$net view \\<computer>

List all current network connections and mapped drives

$net use

Map a network share to a drive letter

$net use <drive>: \\<host>\<share>

Disconnect a mapped network drive

$net use <drive>: /delete

Display all shared resources on the local computer

$net share

Create a new network share

$net share <name>=<path>

Delete an existing network share

$net share <name> /delete

Display the ARP cache showing IP-to-MAC mappings

$arp -a

Delete a specific entry from the ARP cache

$arp -d <ip>

Add a static ARP entry

$arp -s <ip> <mac>

Display the full routing table

$route print

Add a new route to the routing table

$route add <destination> mask <mask> <gateway>

Delete a route from the routing table

$route delete <destination>

List all saved Wi-Fi profiles

$netsh wlan show profiles

Display a Wi-Fi profile including the saved password

$netsh wlan show profile name="<ssid>" key=clear

Connect to a saved Wi-Fi network

$netsh wlan connect name="<ssid>"

Disconnect from the current Wi-Fi network

$netsh wlan disconnect

Set a static IP address on a network adapter

$netsh interface ip set address <adapter> static <ip> <mask> <gateway>

Set a network adapter to use DHCP

$netsh interface ip set address <adapter> dhcp

Enable Windows Firewall for all profiles

$netsh advfirewall set allprofiles state on

Disable Windows Firewall for all profiles

$netsh advfirewall set allprofiles state off

Add a firewall rule to allow inbound TCP traffic on a port

$netsh advfirewall firewall add rule name="<n>" protocol=TCP dir=in localport=<port> action=allow

Delete a specific firewall rule by name

$netsh advfirewall firewall delete rule name="<n>"

Open an FTP connection to a remote host

$ftp <host>

Transfer data from a URL (available in Windows 10+)

$curl <url>

Download a URL and save it to a file

$curl -o <file> <url>

User & Account Management

List all local user accounts

$net user

Display detailed information about a specific user account

$net user <username>

Create a new local user account with a password

$net user <username> <password> /add

Delete a local user account

$net user <username> /delete

Change the password for a local user account

$net user <username> <password>

Enable a disabled user account

$net user <username> /active:yes

Disable a user account

$net user <username> /active:no

Require a password for a user account

$net user <username> /passwordreq:yes

Set an expiration date for a user account

$net user <username> /expires:<date>

List all local groups

$net localgroup

Display members of a specific local group

$net localgroup <group>

Add a user to a local group

$net localgroup <group> <user> /add

Remove a user from a local group

$net localgroup <group> <user> /delete

Create a new local group

$net localgroup <group> /add

Delete a local group

$net localgroup <group> /delete

Run a command as a different user

$runas /user:<domain>\<user> <command>

Run a command as the Administrator user

$runas /user:Administrator <command>

Display password and logon policy for the local computer

$net accounts

Set the maximum password age in days

$net accounts /maxpwage:<days>

Set the minimum password length

$net accounts /minpwlen:<length>

Services Management

List the status of all services

$sc query

Display the status of a specific service

$sc query <service>

List all services and drivers

$sc query type= all

List all services regardless of their state

$sc query state= all

Start a service

$sc start <service>

Stop a running service

$sc stop <service>

Pause a running service

$sc pause <service>

Resume a paused service

$sc continue <service>

Set a service to start automatically

$sc config <service> start= auto

Set a service to start manually

$sc config <service> start= demand

Disable a service from starting

$sc config <service> start= disabled

Create a new service with a binary path

$sc create <service> binPath= "<path>"

Mark a service for deletion

$sc delete <service>

Set a description for a service

$sc description <service> "<desc>"

List all currently running services

$net start

Start a Windows service by name

$net start <service>

Stop a Windows service by name

$net stop <service>

Pause a running service

$net pause <service>

Continue a paused service

$net continue <service>

Disk & Storage

Open the interactive disk partitioning tool

$diskpart

Check the current drive for errors

$chkdsk

Check a specific drive for file system errors

$chkdsk <drive>:

Check and fix file system errors on a drive

$chkdsk <drive>: /f

Locate bad sectors and recover readable data

$chkdsk <drive>: /r

Force dismount before checking (use with /f)

$chkdsk <drive>: /x

Format a disk drive

$format <drive>:

Format a drive with the NTFS file system

$format <drive>: /fs:NTFS

Format a drive with the FAT32 file system

$format <drive>: /fs:FAT32

Quick format a drive

$format <drive>: /q

Set or change the volume label of a drive

$label <drive>: <name>

Display the volume label and serial number of a drive

$vol <drive>:

Display free and total disk space for a drive

$fsutil volume diskfree <drive>:

Create a new file of a specified size in bytes

$fsutil file createnew <file> <size>

Assign a drive letter to a folder path

$subst <drive>: <path>

Remove a substituted drive letter

$subst <drive>: /d

List all current drive substitutions

$subst

Defragment a drive with progress reporting

$defrag <drive>: /u /v

Analyze a drive without defragmenting

$defrag <drive>: /a

Batch Scripting

Turn off command echoing for the rest of the script

$@echo off

Print a message to the console

$echo <message>

Print a blank line to the console

$echo.

Print the value of a variable

$echo %<variable>%

Set a variable in the current batch session

$set <variable>=<value>

Prompt the user to input a value for a variable

$set /p <variable>=<prompt>

Evaluate an arithmetic expression and store the result

$set /a <variable>=<expression>

Execute a command if a condition is true

$if <condition> <command>

Execute a command if a file exists

$if exist <file> <command>

Execute a command if a file does not exist

$if not exist <file> <command>

Execute a command if a variable equals a value

$if %<variable>%==<value> <command>

Case-insensitive comparison of a variable to a value

$if /i %<variable>%==<value> <command>

Execute a command if the previous command succeeded

$if %errorlevel%==0 <command>

Execute a command if a variable is defined

$if defined <variable> <command>

Execute a command if a variable is not defined

$if not defined <variable> <command>

Execute a command if n1 is greater than n2

$if <n1> gtr <n2> <command>

Execute a command if n1 is less than n2

$if <n1> lss <n2> <command>

Execute a command if n1 equals n2

$if <n1> equ <n2> <command>

Execute a command if n1 does not equal n2

$if <n1> neq <n2> <command>

Loop through a set of values

$for %i in (<set>) do <command>

Numeric for loop from start to end with step increment

$for /l %i in (<start>,<step>,<end>) do <command>

Loop through each line of a file

$for /f %i in (<file>) do <command>

Loop through the output of a command

$for /f "tokens=*" %i in ('<command>') do <cmd>

Recursively loop through files matching a pattern

$for /r <path> %i in (<pattern>) do <command>

Loop through matching directories only

$for /d %i in (<pattern>) do <command>

Jump script execution to a labelled section

$goto <label>

Define a label to jump to with goto

$:<label>

Call and run another batch script

$call <script>.bat

Call a subroutine defined in the same batch file

$call :<subroutine>

Exit the current batch script with an exit code

$exit /b <code>

Exit the command prompt session with an exit code

$exit <code>

Get the first argument passed to the script, removing quotes

$%~1

Get the drive and path of the batch file itself

$%~dp0

Get the fully qualified path of the first argument

$%~f1

Get the filename without extension from the first argument

$%~n1

Get the file extension from the first argument

$%~x1

Pause execution and wait for the user to press a key

$pause

Prompt the user to press one of a set of characters

$choice /c <chars> /m <message>

Begin local environment changes in a script

$setlocal

End local environment changes and restore original environment

$endlocal

Enable delayed variable expansion using !variable! syntax

$setlocal enabledelayedexpansion

Enable command extensions for enhanced batch features

$enableextensions

Add a comment to a batch script (not executed)

$rem <comment>

Add a comment using the double-colon syntax

$:: <comment>

Redirection & Pipelines

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> < <file>

Redirect error output to a file

$<command> 2> <file>

Append error output to a file

$<command> 2>> <file>

Redirect stderr to the same destination as stdout

$<command> 2>&1

Redirect both stdout and stderr to a file

$<command> > <file> 2>&1

Discard standard output

$<command> > nul

Discard both standard output and error output

$<command> > nul 2>&1

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

$<command1> & <command2>

Pipe the output of a command to the clipboard

$<command> | clip

Pipe output through the more pager

$<command> | more

Pipe output and filter for a specific string

$<command> | find "<string>"

Pipe output and filter using a pattern or regex

$<command> | findstr "<pattern>"

Pipe output and sort it alphabetically

$<command> | sort

Pipe output and sort it in reverse order

$<command> | sort /r

System Administration

Shut down the local computer

$shutdown /s

Shut down the computer after a specified delay

$shutdown /s /t <seconds>

Restart the local computer

$shutdown /r

Hibernate the local computer

$shutdown /h

Log off the current user

$shutdown /l

Abort a pending shutdown

$shutdown /a

Remotely shut down another computer

$shutdown /m \\<computer> /s

Restart into the Advanced Boot Options menu

$shutdown /r /o

Refresh Group Policy settings

$gpupdate

Force a full refresh of all Group Policy settings

$gpupdate /force

Display the Resultant Set of Policy for the current user

$gpresult /r

Generate an HTML Group Policy report

$gpresult /h <file>.html

Scan and repair protected Windows system files

$sfc /scannow

Scan system files for integrity without repairing

$sfc /verifyonly

Scan and repair the Windows image using DISM

$dism /online /cleanup-image /restorehealth

Scan the Windows image for corruption

$dism /online /cleanup-image /scanhealth

Check if the Windows image is flagged as corrupted

$dism /online /cleanup-image /checkhealth

Query and display registry key values

$reg query <key>

Query a specific registry value

$reg query <key> /v <valuename>

Add or update a registry value

$reg add <key> /v <name> /t <type> /d <data>

Delete a specific registry value

$reg delete <key> /v <valuename>

Delete a registry key and all its values

$reg delete <key>

Export a registry key to a .reg file

$reg export <key> <file>.reg

Import a .reg file into the registry

$reg import <file>.reg

Copy a registry key and all its subkeys to another location

$reg copy <source> <destination>

Open the graphical Registry Editor

$regedit

Open the System Configuration tool

$msconfig

Open the Event Viewer

$eventvwr

Open the Device Manager

$devmgmt.msc

Open the Services management console

$services.msc

Open the Computer Management console

$compmgmt.msc

Open the Disk Management console

$diskmgmt.msc

Open the Task Scheduler

$taskschd.msc

Open the Control Panel

$control

Open a specific Control Panel applet

$control <applet>

Force Windows Update to check for updates immediately

$wuauclt /detectnow

Display and manage the boot configuration data

$bcdedit

List all boot entries in the boot configuration

$bcdedit /enum

Miscellaneous

Clear the command prompt screen

$cls

Display a list of built-in CMD commands with brief descriptions

$help

Display help documentation for a specific command

$help <command>

Display help and usage information for any command

$<command> /?

Change the foreground and background colors of the console

$color <attr>

Set black background with green text

$color 0a

Set the title of the current command prompt window

$title <text>

Change the command prompt text

$prompt <text>

Reset the prompt to show current directory and >

$prompt $P$G

Set the console window size in columns and lines

$mode con cols=<n> lines=<n>

Create a command alias (macro) in CMD

$doskey <alias>=<command>

Display the command history for the current session

$doskey /history

List all currently defined macros

$doskey /macros

Copy stdin or piped output to the Windows clipboard

$clip

Sort the lines of input alphabetically

$sort

Sort the lines of input in reverse order

$sort /r

Sort starting from character position <n>

$sort /+<n>

Display all file extension associations

$assoc

Display the file type associated with an extension

$assoc .<ext>

Associate a file extension with a file type

$assoc .<ext>=<filetype>

Display all file type open commands

$ftype

Display the open command for a specific file type

$ftype <filetype>

Set the open command for a file type

$ftype <filetype>=<command>

Find the location of an executable in the PATH

$where <command>

Compute the MD5 hash of a file

$certutil -hashfile <file> MD5

Compute the SHA256 hash of a file

$certutil -hashfile <file> SHA256

Base64-encode a file

$certutil -encode <infile> <outfile>

Base64-decode a file

$certutil -decode <infile> <outfile>

Encrypt a file using NTFS EFS encryption

$cipher /e <file>

Decrypt an EFS-encrypted file

$cipher /d <file>

Securely wipe free space on a drive

$cipher /w:<path>

Compare two files byte by byte

$fc /b <file1> <file2>

Generate a detailed battery usage report

$powercfg /batteryreport

Analyze power usage and generate an energy report

$powercfg /energy

List all available power plans

$powercfg /list

Set the active power plan

$powercfg /setactive <scheme>