The Windows command line is still the fastest way to fix network problems, find files, check your system and automate boring tasks. This guide covers the commands developers and power users actually use on Windows 10 and Windows 11, with the Command Prompt (CMD) version and the PowerShell equivalent side by side.
How to open the command line
- Quickest: press Win+R, type
cmdorpowershell, press Enter. - As administrator: press Win+X and choose Terminal (Admin). Commands that change system settings need this.
- In a folder: in File Explorer, click the address bar, type
cmdand press Enter to open CMD already in that folder.
Navigating folders and files
| Task | CMD | PowerShell |
|---|---|---|
| Show current folder | cd | Get-Location (or pwd) |
| List files | dir | Get-ChildItem (or ls) |
| Change folder | cd C:\Projects | cd C:\Projects |
| Go up one level | cd .. | cd .. |
| Switch drive | D: | D: |
| Create folder | mkdir logs | New-Item -ItemType Directory logs |
| Copy file | copy a.txt b.txt | Copy-Item a.txt b.txt |
| Move / rename | move a.txt old\ / ren a.txt b.txt | Move-Item / Rename-Item |
| Delete file | del a.txt | Remove-Item a.txt |
| Show file contents | type notes.txt | Get-Content notes.txt |
| Clear screen | cls | cls |
:: list everything, including hidden files, one page at a time
dir /a | more
:: show the folder tree
tree C:\Projects /f
Finding files and text
# find every .log file under the current folder
Get-ChildItem -Recurse -Filter *.log
# the 10 largest files under C:\Users\you\Downloads
Get-ChildItem "$env:USERPROFILE\Downloads" -Recurse -File |
Sort-Object Length -Descending | Select-Object -First 10 Name, @{n='MB';e={[math]::Round($_.Length/1MB,1)}}
# search inside files for a word (like grep)
Select-String -Path .\src\*.js -Pattern "TODO"
:: CMD version: search text in files
findstr /s /i "TODO" *.js
Network troubleshooting
| Command | What it does |
|---|---|
ipconfig | Shows your IP address, gateway and DNS servers. |
ipconfig /flushdns | Clears the DNS cache. Fixes many "site won't load" problems after DNS changes. |
ping google.com | Checks if you can reach a host and how fast. |
tracert google.com | Shows every hop between you and a host. |
nslookup example.com | Shows what IP a domain points to. |
netstat -ano | Lists open connections and the process ID using each port. |
# is a port open on a server? (great for testing web servers and databases)
Test-NetConnection example.com -Port 443
# which program is using port 3000?
Get-Process -Id (Get-NetTCPConnection -LocalPort 3000).OwningProcess
Processes and services
:: list running programs
tasklist
:: force-close a frozen app by name or PID
taskkill /im chrome.exe /f
taskkill /pid 4512 /f
# top 5 processes by memory
Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 5 Name, Id, @{n='MB';e={[int]($_.WorkingSet/1MB)}}
# check and restart a service (run as admin)
Get-Service -Name Spooler
Restart-Service -Name Spooler
System information and repair
| Command | What it does |
|---|---|
systeminfo | Windows version, install date, RAM, last boot time. |
winver | Opens a window with the exact Windows build. |
sfc /scannow | Scans and repairs corrupted Windows system files (admin). |
DISM /Online /Cleanup-Image /RestoreHealth | Repairs the Windows image that sfc uses. Run it before sfc if sfc can't fix things (admin). |
chkdsk C: /f | Checks the disk for errors. Runs at next restart for the system drive (admin). |
powercfg /batteryreport | Creates an HTML report of your laptop battery's health. |
shutdown /r /t 0 | Restarts immediately. /s shuts down instead. |
Installing software with winget
Windows 10 and 11 include winget, a package manager. It installs and updates apps without visiting websites:
winget search vscode
winget install Microsoft.VisualStudioCode
winget install Git.Git OpenJS.NodeJS.LTS Python.Python.3.12
# update every app that has an update
winget upgrade --all
Environment variables and PATH
# show PATH, one folder per line
$env:Path -split ';'
# where is a program installed?
Get-Command node
where.exe python
A tiny automation example
Save this as backup.ps1 to copy a project folder into a dated backup folder:
$source = "C:\Projects\my-site"
$dest = "D:\Backups\my-site-$(Get-Date -Format yyyy-MM-dd)"
Copy-Item $source $dest -Recurse
Write-Host "Backed up to $dest"
Run it with powershell -ExecutionPolicy Bypass -File .\backup.ps1, or schedule it with Task Scheduler.
del, Remove-Item -Recurse, format and diskpart don't use the Recycle Bin. Double-check the path before pressing Enter.Handy shortcuts
- Tab completes file and folder names.
- ↑ / ↓ scroll through previous commands.
- Ctrl+C stops a running command.
- Add
/?to any CMD command (dir /?) or useGet-Helpin PowerShell (Get-Help Copy-Item -Examples) to see its options.
Which command do you use most? Share it in the comments.
Outstanding post!
ReplyDeleteYou described it well.
ReplyDelete