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

  1. Windows: press Win + X > Terminal. For admin rights choose Terminal (Admin).
  2. Command Prompt: Win + R, type cmd, Enter. Ctrl + Shift + Enter opens it as administrator.
  3. Linux: Ctrl + Alt + T. macOS: Cmd + Space, type Terminal.

Command Prompt (CMD)

dirList files in the current folder
cd foldername / cd ..Go into a folder / one folder up
copy a.txt b.txtCopy a file
move a.txt D:\backup\Move a file
del file.txtDelete a file (not to the Recycle Bin)
mkdir newfolderMake a folder
clsClear the screen
ipconfig /allNetwork details: IP address, DNS, adapter
ipconfig /flushdnsClear the DNS cache (fixes some sites not opening)
ping google.comCheck if the internet works
tracert google.comSee where the connection is slow
netsh wlan show profilesSaved Wi-Fi networks
systeminfoWindows version, RAM, install date
tasklist / taskkill /im name.exe /fList programs / force-close one
shutdown /r /t 0Restart now
chkdsk C: /fCheck the disk for errors (at next restart)
sfc /scannowRepair Windows system files (admin)
winget upgrade --allUpdate all programs that winget knows

PowerShell

Get-ChildItemList files (same as dir / ls)
Get-Process | Sort CPU -Descending | Select -First 1010 programs using the most CPU
Stop-Process -Name notepadClose a program
Get-Service | Where Status -eq RunningServices that are running
Get-FileHash file.iso -Algorithm SHA256Checksum of a download (compare it with the official one)
Test-NetConnection google.com -Port 443Test a connection to a website
Get-ComputerInfo | Select OsName, OsVersionWindows edition and version
Get-PhysicalDiskDisks and their health status
Get-AppxPackage *xbox* | Remove-AppxPackageRemove a built-in app for this user (careful: only apps you are sure about)
Restart-ComputerRestart

Linux and macOS terminal

ls -laList all files with details
cd ~/DownloadsGo to a folder (~ is your home folder)
pwdShow where you are
cp a.txt b.txt / mv a.txt dir/Copy / move
rm file.txt / rm -r folderDelete a file / a folder (no Recycle Bin)
mkdir -p a/b/cMake folders
cat file.txt / less file.txtShow a file
grep -i "word" file.txtFind text in a file
df -h / du -sh *Free disk space / folder sizes
top / htopRunning programs and CPU use
sudo apt update && sudo apt upgradeUpdate Ubuntu / Mint / Debian
sudo dnf upgradeUpdate Fedora
brew upgradeUpdate programs on macOS (Homebrew)
ip a / ifconfigNetwork details
sha256sum file.iso / shasum -a 256 file.isoChecksum on Linux / macOS
chmod +x script.shMake 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.