Skip to content

All CMD Commands for Windows

Basics 23

Get started

help
Lists the built-in commands.
ipconfig /?
Shows any command's options.
cls
Clears the screen.
exit
Closes Command Prompt.
ver
Shows your Windows version.

Move around

cd
Shows the folder you are in.
cd Documents
Opens a folder.
cd ..
Goes up one folder.
cd \
Goes to the top of the drive.
d:
Switches to drive D.
cd /d D:\Projects
Switches drive and folder at once.
pushd D:\Projects
Saves this folder and opens another.
popd
Goes back to the saved folder.

Handy tricks

start .
Opens this folder in File Explorer.
start notepad
Opens an app.
where notepad
Shows where a program is.
doskey /history
Lists the commands you typed.
ipconfig | clip
Copies a command's output.
ipconfig > info.txt
Saves the output to a file.
ipconfig >> info.txt
Adds the output to a file.
title Backup
Renames the window.
color 0a
Green text on black.
color
Puts the colors back.

Files and folders 43

See files

dir
Lists files and folders.
dir /a
Includes hidden files.
dir /s /b *.pdf
Finds every PDF in all subfolders.
dir /o:-s
Biggest files first.
dir /o:-d
Newest files first.
tree /f
Shows folders and files as a tree.
type notes.txt
Shows a text file.
more log.txt
Shows a long file one page at a time.

Create and delete

md Projects
Creates a folder.
md Projects\2026\Photos
Creates folders inside folders.
ren notes.txt todo.txt
Renames a file.
ren *.txt *.md
Changes the extension of many files.
move notes.txt D:\Backup
Moves a file.
del notes.txt
Deletes a file, skipping the Recycle Bin.
del /s /q *.tmp
Deletes every .tmp file in subfolders.
rd Projects
Removes an empty folder.
rd /s /q Projects
Removes a folder and everything in it.

Copy and back up

copy notes.txt D:\Backup
Copies a file.
copy *.jpg D:\Photos
Copies every JPG.
copy a.txt+b.txt all.txt
Joins two files into one.
xcopy D:\Photos E:\Photos /e /h /i
Copies a folder with hidden files.
robocopy D:\Photos E:\Photos /e
Copies a folder and all subfolders.
robocopy D:\Photos E:\Photos /mir
Mirrors a folder, deleting extra files.
robocopy D:\Photos E:\Photos /e /z
Copies big files, resuming if cut off.
robocopy D:\Photos E:\Photos /e /mt:16
Copies with 16 threads, much faster.
robocopy D:\Photos E:\Photos /e /xo
Skips files that are older.

Find and compare

find "error" log.txt
Finds a word in a file.
findstr /s /i "invoice" *.txt
Searches all subfolders, any case.
findstr /n "TODO" app.js
Shows matches with line numbers.
fc old.txt new.txt
Compares two text files.
fc /b a.jpg b.jpg
Compares two files byte by byte.
certutil -hashfile setup.exe SHA256
Shows a file's SHA-256 hash.
sort names.txt
Sorts the lines of a file.

Hidden files and permissions

attrib +h secret.txt
Hides a file.
attrib -h secret.txt
Unhides it.
attrib -h -s -r E:\*.* /s /d
Unhides everything on a USB drive.
takeown /f D:\Old /r /d y
Makes you the owner of a folder.
icacls D:\Old
Shows who can open a folder.
icacls D:\Old /reset /t
Resets a folder's permissions.
mklink /j C:\Games D:\Games
Links a folder to another drive.
subst X: D:\Projects
Shows a folder as drive X.
subst X: /d
Removes that drive.
forfiles /p D:\Logs /d -30 /c "cmd /c del @path"
Deletes files older than 30 days.

Repair and clean up 23

Repair Windows

sfc /scannow
Finds and fixes broken system files (as admin).
sfc /verifyonly
Checks them without fixing.
DISM /Online /Cleanup-Image /CheckHealth
Quick check for a damaged Windows.
DISM /Online /Cleanup-Image /ScanHealth
Deeper check. Takes a few minutes.
DISM /Online /Cleanup-Image /RestoreHealth
Repairs Windows from Windows Update.

Check the drive

chkdsk
Checks the drive without fixing.
chkdsk C: /scan
Scans while you keep working.
chkdsk C: /f
Fixes errors. Drive C waits for a restart.
chkdsk D: /r
Also finds bad sectors.
fsutil dirty query C:
Shows if a check is pending.

Free up space

cleanmgr
Opens Disk Cleanup.
cleanmgr /sageset:1
Picks what to clean.
cleanmgr /sagerun:1
Cleans using those picks.
cleanmgr /verylowdisk
Cleans with no questions.
del /q /f /s %TEMP%\*
Clears your temp files.
DISM /Online /Cleanup-Image /StartComponentCleanup
Removes old update files (as admin).
DISM /Online /Cleanup-Image /StartComponentCleanup /ResetBase
Removes more, but updates can't be uninstalled.
powercfg /hibernate off
Turns off hibernation and frees its space.

Speed up drives

defrag C: /a
Checks if a drive needs it.
defrag C: /o
Optimizes a drive, HDD or SSD.
defrag /c /o
Optimizes every drive.
defrag C: /l
Runs TRIM on an SSD.
cipher /w:C:\
Wipes deleted files from free space.

Drives and disks 20

Drive info

fsutil fsinfo drives
Lists every drive letter.
fsutil volume diskfree C:
Shows free and used space.
vol
Shows the drive's name and serial.
label E: Backup
Renames a drive.
manage-bde -status
Shows BitLocker status.
manage-bde -protectors -get C:
Shows your BitLocker recovery key.

Format a drive

Formatting erases the drive.

format E: /fs:exfat /q
Erases a USB drive for any computer.
format E: /fs:ntfs /q
Erases a drive as NTFS.

Diskpart

Type these after diskpart. Clean erases everything, so check the disk number.

diskpart
Opens the disk tool (as admin).
list disk
Lists your disks.
select disk 1
Picks disk 1.
list volume
Lists drives and partitions.
list partition
Lists the disk's partitions.
attributes disk clear readonly
Removes write protection.
clean
Erases the whole disk.
convert gpt
Makes an empty disk GPT.
create partition primary
Creates a partition.
format fs=ntfs quick label=Backup
Formats it.
assign letter=E
Gives it a drive letter.
exit
Leaves Diskpart.

Network and Wi-Fi 33

IP and DNS

ipconfig
Shows your IP address.
ipconfig /all
Adds MAC address, DNS and more.
ipconfig /release
Drops your IP address.
ipconfig /renew
Gets a new one.
ipconfig /flushdns
Clears the DNS cache.
ipconfig /displaydns
Shows the DNS cache.
nslookup techpp.app
Looks up a site's IP address.
nslookup techpp.app 1.1.1.1
Asks a different DNS server.

Test a connection

ping google.com
Checks if a site answers.
ping /t google.com
Keeps pinging until Ctrl+C.
ping /n 10 google.com
Pings 10 times.
tracert google.com
Shows every hop on the way.
pathping google.com
Finds where packets get lost.

Connections and ports

netstat -ano
Lists connections with process IDs.
netstat -b
Shows the app behind each one (as admin).
netstat -e
Shows data sent and received.
arp -a
Lists devices your PC has seen nearby.
getmac
Shows MAC addresses.
route print
Shows the routing table.

Wi-Fi

netsh wlan show profiles
Lists saved Wi-Fi networks.
netsh wlan show profile name="Home WiFi" key=clear
Shows a saved Wi-Fi password.
netsh wlan show interfaces
Shows signal and speed.
netsh wlan show networks
Lists Wi-Fi networks nearby.
netsh wlan show drivers
Shows what your Wi-Fi card supports.
netsh wlan show wlanreport
Builds a Wi-Fi history report.
netsh wlan connect name="Home WiFi"
Joins a saved network.
netsh wlan disconnect
Leaves Wi-Fi.
netsh wlan delete profile name="Home WiFi"
Forgets a network.
netsh wlan export profile folder=C:\WiFi key=clear
Backs up every network with passwords.

Reset the network

netsh winsock reset
Fixes broken internet. Restart after.
netsh interface ipv4 reset
Resets IP settings. Restart after.
netsh advfirewall reset
Resets Windows Firewall rules.
netsh interface ipv4 show interfaces
Lists network adapters.

System info 34

About this PC

systeminfo
Shows Windows, RAM, install date and more.
systeminfo | findstr /c:"OS Name" /c:"Total Physical Memory"
Just the Windows edition and RAM.
hostname
Shows the PC's name.
whoami
Shows who you are signed in as.
msinfo32
Opens System Information.
tpmtool getdeviceinformation
Shows TPM details.
date /t
Shows the date.
time /t
Shows the time.
tzutil /g
Shows the time zone.
set
Lists environment variables.
path
Shows where Windows looks for programs.

Drivers

driverquery
Lists installed drivers.
driverquery /v
Adds status and file paths.
pnputil /enum-drivers
Lists added driver packages.
pnputil /enum-devices /problem
Lists devices with problems.
pnputil /scan-devices
Looks for new hardware.

Running apps

tasklist
Lists running apps.
tasklist /svc
Shows services in each one.
tasklist /fi "memusage gt 500000"
Apps using over 500 MB.
taskkill /im notepad.exe /f
Force closes an app.
taskkill /pid 1234 /f
Force closes by process ID.
taskkill /im chrome.exe /t /f
Closes an app and all its windows.

Battery and sleep

powercfg /batteryreport
Builds a battery health report.
powercfg /energy
Finds power problems (as admin).
powercfg /sleepstudy
Shows what drained the battery in sleep.
powercfg /requests
Shows what is keeping the PC awake.
powercfg /lastwake
Shows what woke the PC.
powercfg /devicequery wake_armed
Lists devices that can wake it.
powercfg /a
Lists the sleep modes it supports.

Logs

wevtutil qe System /c:10 /rd:true /f:text
Shows the 10 newest system events.
perfmon /rel
Opens Reliability Monitor.
perfmon /res
Opens Resource Monitor.
perfmon /report
Builds a 60-second health report.
gpresult /r
Shows the policies applied to you.

Apps and services 27

Install apps with WinGet

winget search powertoys
Finds an app.
winget install Microsoft.PowerToys
Installs it.
winget show Microsoft.PowerToys
Shows details about it.
winget list
Lists installed apps.
winget upgrade
Lists apps with updates.
winget upgrade --all
Updates every app.
winget uninstall Microsoft.PowerToys
Removes an app.
winget export -o apps.json
Saves a list of your apps.
winget import -i apps.json
Installs them on a new PC.

Services

net start
Lists running services.
sc query spooler
Shows one service's status.
net stop spooler
Stops a service (as admin).
net start spooler
Starts it again.
sc config spooler start= disabled
Stops it starting with Windows.
sc config spooler start= auto
Starts it with Windows again.

Scheduled tasks

schtasks /query
Lists scheduled tasks.
schtasks /create /sc daily /tn "Backup" /tr "C:\Scripts\backup.bat" /st 21:00
Runs a script every day at 9 PM.
schtasks /run /tn "Backup"
Runs a task now.
schtasks /delete /tn "Backup" /f
Deletes a task.

Registry

reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
Lists your startup apps.
reg export HKCU\Software\MyApp backup.reg
Backs up a registry key.
reg import backup.reg
Restores it.
reg add HKCU\Software\MyApp /v Theme /t REG_SZ /d Dark
Adds a value.
reg delete HKCU\Software\MyApp /v Theme /f
Deletes a value.

Open Windows tools

mstsc
Opens Remote Desktop.
mstsc /v:192.168.1.20
Connects to a PC by its IP.
assoc .txt
Shows a file type's name.

Power and users 24

Shut down and restart

shutdown /s /t 0
Shuts down now.
shutdown /r /t 0
Restarts now.
shutdown /s /t 3600
Shuts down in one hour.
shutdown /a
Cancels a timed shutdown.
shutdown /l
Signs you out.
shutdown /h
Hibernates.
shutdown /r /o /t 0
Restarts into recovery options.
shutdown /r /fw /t 0
Restarts into BIOS or UEFI.

Power plans

powercfg /list
Lists power plans.
powercfg /getactivescheme
Shows the plan in use.
powercfg /change monitor-timeout-ac 5
Screen off after 5 minutes plugged in.
powercfg /change standby-timeout-dc 15
Sleep after 15 minutes on battery.
powercfg /hibernate on
Turns hibernation on.

User accounts

net user
Lists accounts on this PC.
net user Alex
Shows one account's details.
net user Alex *
Changes its password (as admin).
net user Alex * /add
Adds an account.
net user Alex /active:no
Turns an account off.
net user Alex /delete
Deletes an account.
net localgroup administrators
Lists admins.
net localgroup administrators Alex /add
Makes someone an admin.
net accounts
Shows password rules.
quser
Lists who is signed in.
cmdkey /list
Lists saved sign-ins.

Batch files 27

Script basics

@echo off
Hides each command as it runs.
echo Hello
Prints text.
rem Daily backup
Adds a comment.
pause
Waits for a key press.
timeout /t 10
Waits 10 seconds.
timeout /t 10 /nobreak
Waits, ignoring key presses.
call other.bat
Runs another script, then comes back.
start /wait setup.exe
Runs a program and waits for it.
exit /b 0
Ends the script.

Variables

set name=Alex
Sets a variable.
echo %name%
Uses it.
set /p name=Your name:
Asks the user for a value.
set /a total=5+3
Does math.
setx MY_FOLDER D:\Projects
Saves a variable for good.
echo %~dp0
The script's own folder.
echo %errorlevel%
The last command's exit code.
setlocal
Keeps changes inside the script.
endlocal
Ends that.

Choices and loops

In a .bat file use %%f. Typed at the prompt it is %f.

if exist notes.txt echo Found
Checks if a file exists.
if "%name%"=="Alex" echo Hi
Compares text.
if errorlevel 1 echo Failed
Checks if the last command failed.
choice /c yn /m "Continue?"
Asks Y or N.
goto end
Jumps to the :end label.
for %%f in (*.txt) do echo %%f
Loops over files.
for /l %%i in (1,1,5) do echo %%i
Counts from 1 to 5.
for /f "tokens=*" %%a in (list.txt) do echo %%a
Reads a file line by line.
shift
Moves to the next argument.