Command line cheat sheet: CMD, PowerShell and Linux terminal
The most useful commands for Command Prompt, PowerShell and the Linux / macOS terminal, with what each one does.
Open the command line
- Windows: press Win + X > Terminal. For admin rights choose Terminal (Admin).
- Command Prompt: Win + R, type cmd, Enter. Ctrl + Shift + Enter opens it as administrator.
- Linux: Ctrl + Alt + T. macOS: Cmd + Space, type Terminal.
Command Prompt (CMD)
dir | List files in the current folder |
cd foldername / cd .. | Go into a folder / one folder up |
copy a.txt b.txt | Copy a file |
move a.txt D:\backup\ | Move a file |
del file.txt | Delete a file (not to the Recycle Bin) |
mkdir newfolder | Make a folder |
cls | Clear the screen |
ipconfig /all | Network details: IP address, DNS, adapter |
ipconfig /flushdns | Clear the DNS cache (fixes some sites not opening) |
ping google.com | Check if the internet works |
tracert google.com | See where the connection is slow |
netsh wlan show profiles | Saved Wi-Fi networks |
systeminfo | Windows version, RAM, install date |
tasklist / taskkill /im name.exe /f | List programs / force-close one |
shutdown /r /t 0 | Restart now |
chkdsk C: /f | Check the disk for errors (at next restart) |
sfc /scannow | Repair Windows system files (admin) |
winget upgrade --all | Update all programs that winget knows |
PowerShell
Get-ChildItem | List files (same as dir / ls) |
Get-Process | Sort CPU -Descending | Select -First 10 | 10 programs using the most CPU |
Stop-Process -Name notepad | Close a program |
Get-Service | Where Status -eq Running | Services that are running |
Get-FileHash file.iso -Algorithm SHA256 | Checksum of a download (compare it with the official one) |
Test-NetConnection google.com -Port 443 | Test a connection to a website |
Get-ComputerInfo | Select OsName, OsVersion | Windows edition and version |
Get-PhysicalDisk | Disks and their health status |
Get-AppxPackage *xbox* | Remove-AppxPackage | Remove a built-in app for this user (careful: only apps you are sure about) |
Restart-Computer | Restart |
Linux and macOS terminal
ls -la | List all files with details |
cd ~/Downloads | Go to a folder (~ is your home folder) |
pwd | Show where you are |
cp a.txt b.txt / mv a.txt dir/ | Copy / move |
rm file.txt / rm -r folder | Delete a file / a folder (no Recycle Bin) |
mkdir -p a/b/c | Make folders |
cat file.txt / less file.txt | Show a file |
grep -i "word" file.txt | Find text in a file |
df -h / du -sh * | Free disk space / folder sizes |
top / htop | Running programs and CPU use |
sudo apt update && sudo apt upgrade | Update Ubuntu / Mint / Debian |
sudo dnf upgrade | Update Fedora |
brew upgrade | Update programs on macOS (Homebrew) |
ip a / ifconfig | Network details |
sha256sum file.iso / shasum -a 256 file.iso | Checksum on Linux / macOS |
chmod +x script.sh | Make a script runnable |
Safety
Never paste commands from strangers, videos or chat messages that you do not understand, especially lines with "iwr", "curl ... | sh", "Invoke-Expression" or "Set-ExecutionPolicy Unrestricted". Scammers use them to install malware.