Software & OS

CMD Commands List: 45 Essential Windows Command Prompt Commands

The CMD commands you will use most are dir (list files), cd (change folder), copy, move, del, mkdir, ipconfig, ping, tasklist, taskkill and systeminfo. Type help in Command Prompt for a list, and add /? to any command (such as dir /?) for its full syntax.

The tables below group 45 commands by job. Outputs shown are example output from Windows 11 (build 22631), with paths shortened. Commands marked "admin" need a Command Prompt opened with Run as administrator.

Files and folders

CommandWhat it doesExample
dirList files and foldersdir /a (include hidden), dir /s *.pdf (search subfolders)
cdShow or change the current foldercd .., cd /d D:\work
mkdir / mdCreate a foldermkdir reports\2026
rmdir / rdDelete a folderrmdir old (must be empty), rmdir /s old
copyCopy filescopy notes.txt D:\backup\
xcopyCopy files and folder treesxcopy C:\src D:\dst /e /i
robocopyCopy large trees, resumable, with loggingrobocopy C:\src D:\dst /e /z
moveMove or rename files and foldersmove report.docx archive\
renRename a fileren draft.txt final.txt
del / eraseDelete files (not to the Recycle Bin)del *.tmp
typePrint a text filetype notes.txt
moreShow output one screen at a timetype log.txt | more
treeDraw the folder structuretree /f (include files)
attribShow or change file attributesattrib -h -s file.txt
findstrSearch text in filesfindstr /s /i "error" *.log
whereFind which executable runs for a namewhere python
fcCompare two filesfc old.txt new.txt

Example output of dir in a small folder:

 Directory of C:\work\cmdtest

2026-10-26  14:11    <DIR>          .
2026-10-26  14:11    <DIR>          ..
2026-10-26  14:11                 8 notes.txt
2026-10-26  14:11                 8 old.txt
2026-10-26  14:11    <DIR>          sub
               2 File(s)             16 bytes
               3 Dir(s)  362 145 714 176 bytes free

Two details trip people up. First, cd D:\work from drive C changes D's current folder but leaves you on C; add /d to switch drive too, or type D: first. Second, rmdir refuses a folder that still has files in it and prints The directory is not empty; /s deletes the whole tree.

Networking

CommandWhat it doesExample
ipconfigShow IP address, gateway and DNS settingsipconfig /all
ipconfig /flushdnsClear the DNS cacheipconfig /flushdns
ipconfig /release, /renewDrop and request a DHCP addressipconfig /renew
pingTest whether a host answersping -n 4 example.com
tracertShow each router on the way to a hosttracert example.com
pathpingTrace route plus packet loss per hoppathping example.com
nslookupQuery DNSnslookup example.com
netstatList connections and listening portsnetstat -ano
arpShow the IP-to-MAC address cachearp -a
getmacShow network adapter MAC addressesgetmac /v
netshConfigure networking, firewall, Wi-Finetsh wlan show profiles
hostnamePrint the computer namehostname

More detail: the ping command and flushing the DNS cache. netstat -ano is also the first step in fixing "port already in use".

Processes and the system

CommandWhat it doesExample
tasklistList running processes with PIDstasklist /FI "IMAGENAME eq explorer.exe"
taskkillEnd a processtaskkill /PID 18244 /F, taskkill /IM notepad.exe
systeminfoOS version, install date, RAM, hotfixessysteminfo
verWindows version numberver
whoamiCurrent user (and groups with /groups)whoami
setShow or set environment variables for this windowset PATH
setxSet an environment variable permanentlysetx MY_VAR "value"
sc queryShow Windows service statussc query wuauserv
schtasksList or create scheduled tasksschtasks /query
shutdownShut down, restart or sign outshutdown /r /t 0
clsClear the screencls
exitClose Command Promptexit

Example output:

C:\>ver

Microsoft Windows [Version 10.0.22631.6199]

C:\>tasklist /FI "IMAGENAME eq explorer.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
explorer.exe                 77888 Console                    2    197 792 K

Windows 11 still reports version 10.0 here; the build number (22631) is what identifies the release. Variables set with set vanish when the window closes, while setx writes them permanently but only new windows see them. See setting environment variables for the details.

For shutdown: /s shuts down, /r restarts, /t sets the delay in seconds (default 30), and shutdown /a cancels a pending shutdown during that delay. shutdown /r /fw restarts into the UEFI firmware settings, which saves hunting for the right key at boot.

Disks and system repair

CommandWhat it doesExample
chkdskCheck a disk's file system (admin)chkdsk C: (report only), chkdsk C: /f
sfcVerify and repair protected system files (admin)sfc /scannow
volShow a drive's label and serial numbervol C:
fsutilFile system settings and queries (admin)fsutil behavior query DisableDeleteNotify
diskpartPartition and format disks (admin)Interactive: list disk
defragOptimise a drive: defrag an HDD, TRIM an SSD (admin)defrag C: /o

sfc /scannow "scans the integrity of all protected system files and repairs files with problems when possible", according to Microsoft's reference. chkdsk without switches only reports; /f fixes errors and /r also scans for bad sectors. On the system drive, chkdsk C: /f can't lock the volume, so it asks: Chkdsk cannot run because the volume is in use by another process. Would you like to schedule this volume to be checked the next time the system restarts? (Y/N)

Commands that delete without asking

CMD has no undo, and these do not use the Recycle Bin:

  • del /s /q *.* deletes every file in the folder and all subfolders, silently.
  • rmdir /s /q folder deletes the folder tree with no confirmation. Microsoft's reference warns: "the entire directory tree is deleted without confirmation".
  • robocopy src dst /mir mirrors the source, which means it deletes files in the destination that don't exist in the source. Point it at the wrong destination and it empties it. /mir is documented as /e plus /purge.
  • format and diskpart's clean wipe whole volumes or disks.

Before running any of these, run cd on its own to confirm where you are, and do a dry run where one exists: robocopy's /l switch lists what it would copy or delete without touching anything.

Error messages you'll see

MessageMeaning
'xyz' is not recognized as an internal or external command, operable program or batch file.Typo, or the program's folder isn't in PATH. Check with where xyz.
Access is denied.Needs an administrator prompt, or the file is in use or protected.
The system cannot find the file specified.Wrong name or wrong folder. Run dir to check.
Could Not Find C:\work\missing.txtdel found nothing matching the name.
The directory is not empty.rmdir without /s on a folder with files.

Useful tricks

  • Redirect output to a file: ipconfig /all > network.txt (overwrite) or >> (append).
  • Copy output to the clipboard: systeminfo | clip.
  • Chain commands: a && b runs b only if a succeeded; a & b runs both regardless.
  • Tab completion: press Tab to complete file and folder names.
  • History: the Up arrow recalls earlier commands, and F7 shows a list of them.

If you also work on Linux or macOS, basic Linux commands maps most of these: dir is ls, type is cat, findstr is grep, tasklist is ps.

Frequently asked questions

How do I open Command Prompt?
Press Win+R, type cmd and press Enter. For an administrator prompt, type cmd in the Start menu search, right-click Command Prompt and choose Run as administrator. In Windows Terminal, open a new tab and pick Command Prompt from the drop-down list.
How do I see all CMD commands?
Type help in Command Prompt for a list of common commands with one-line descriptions, then add /? to any command (for example dir /?) for its full syntax. Microsoft Learn's Windows commands reference lists every command alphabetically.
Are CMD commands case-sensitive?
No. DIR, dir and Dir do the same thing, and Windows file names are not case-sensitive by default either. Switches such as /S and /s are also treated the same.
Should I use CMD or PowerShell?
Both run these commands. Microsoft recommends PowerShell for new automation because its cmdlets return objects instead of text, but CMD is still fine for quick one-off commands and existing .bat files. A few CMD built-ins behave differently in PowerShell, where dir and del are aliases for PowerShell cmdlets with different switches.

Sources