Command cheat sheets
192 everyday commands for Windows (PowerShell and CMD) and Linux, grouped by task. Click Copy on any command. Read a command before running it, especially anything marked careful.
Windows 79 commands
System & hardware
systeminfoDetailed OS, hardware and hotfix summary.
Get-ComputerInfoOS, BIOS and hardware properties as objects.
winverShow the Windows version and build in a dialog.
hostnamePrint the computer name.
Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, LastBootUpTimeOS name, build and last boot time.
Get-CimInstance Win32_Processor | Select-Object Name, NumberOfCores, NumberOfLogicalProcessorsCPU model and core counts.
Get-VolumeDrives with file system, size and free space.
Get-PhysicalDiskPhysical disks with health status and media type.
msinfo32Open the System Information console.
devmgmt.mscOpen Device Manager.
diskmgmt.mscOpen Disk Management.
Processes, services & tasks
Get-Process | Sort-Object CPU -Descending | Select-Object -First 10Top 10 processes by CPU time.
tasklistList running processes.
taskkill /PID 1234 /FForce-stop a process by its ID.
Stop-Process -Name notepad -ForceStop processes by name.
Get-Service | Where-Object Status -eq RunningShow running services.
Restart-Service -Name SpoolerRestart a service (example: Print Spooler).
sc query state= allList all services and their state.
services.mscOpen the Services console.
taskschd.mscOpen Task Scheduler.
schtasks /query /fo LISTList scheduled tasks.
Get-WinEvent -LogName System -MaxEvents 20The 20 most recent System log events.
Get-WinEvent -FilterHashtable @{LogName='System'; Level=2; StartTime=(Get-Date).AddDays(-1)}System errors from the last 24 hours.
Networking
ipconfig /allFull IP configuration for every adapter.
ipconfig /flushdnsClear the DNS resolver cache.
ipconfig /release && ipconfig /renewDrop and renew the DHCP lease.
ping -n 4 8.8.8.8Test connectivity with four packets.
tracert example.comShow the route to a host.
pathping example.comPing plus per-hop packet loss.
nslookup example.comQuery DNS.
Resolve-DnsName example.com -Type ADNS query in PowerShell.
Test-NetConnection example.com -Port 443Test whether a TCP port is reachable.
netstat -anoConnections and listening ports with the owning process ID.
Get-NetTCPConnection -State ListenListening TCP ports.
Get-NetAdapterNetwork adapters, status and link speed.
Get-NetIPAddress -AddressFamily IPv4All IPv4 addresses.
netsh wlan show profilesSaved Wi-Fi networks.
netsh winsock resetReset the Winsock catalog (reboot afterwards).
netsh advfirewall show allprofilesWindows Firewall state per profile.
arp -aShow the ARP table.
route printShow the routing table.
Disk, files & repair
sfc /scannowScan and repair protected system files.
DISM /Online /Cleanup-Image /RestoreHealthRepair the component store (run before sfc if sfc fails).
chkdsk C: /scanOnline scan of a volume for errors.
cleanmgrOpen Disk Cleanup.
fsutil volume diskfree C:Free and total space on a volume.
Get-FileHash .\file.iso -Algorithm SHA256Compute a file checksum.
certutil -hashfile file.iso SHA256Compute a checksum from CMD.
Get-ChildItem C:\ -Recurse -File -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 20 FullName, Length20 largest files on C: (slow on big disks).
robocopy C:\src D:\dst /MIR /R:2 /W:2Mirror a folder. Deletes extra files at the destination, so double-check the paths.
mklink /D Link TargetCreate a directory symbolic link.
Users & security
whoami /allCurrent user, SID, groups and privileges.
net userList local user accounts.
net localgroup administratorsMembers of the local Administrators group.
Get-LocalUserLocal accounts and whether they are enabled.
gpupdate /forceRefresh Group Policy now.
gpresult /rSummary of applied Group Policy.
Get-MpComputerStatusMicrosoft Defender status and signature age.
Start-MpScan -ScanType QuickScanRun a Defender quick scan.
manage-bde -statusBitLocker status for each drive.
Updates, packages & power
winget upgradeList available app upgrades.
winget upgrade --allUpgrade everything winget can.
winget search vlcSearch for a package.
winget install VideoLAN.VLCInstall a package by ID.
Get-HotFixInstalled Windows updates (hotfixes).
powercfg /batteryreportWrite a battery health report (HTML) to the current folder.
powercfg /energy60-second energy-efficiency diagnostics report.
shutdown /r /t 0Restart immediately.
shutdown /s /t 0Shut down immediately.
shutdown /aAbort a pending shutdown.
PowerShell basics & WSL
Get-Help Get-Process -ExamplesShow examples for a cmdlet.
Get-Command *service*Find commands by name.
Get-ExecutionPolicy -ListShow the script execution policy at each scope.
Set-ExecutionPolicy RemoteSigned -Scope CurrentUserAllow local scripts for your user only.
Get-History | Select-Object -Last 20Your 20 most recent commands.
wsl --list --verboseInstalled distributions and their WSL version.
wsl --installInstall WSL with the default distribution.
wsl --updateUpdate the WSL kernel.
wsl --shutdownStop all running WSL distributions.
Linux 113 commands
System & hardware
uname -aKernel version and architecture.
cat /etc/os-releaseDistribution name and version.
hostnamectlHostname, OS, kernel and machine information.
uptimeTime since boot and load averages.
lscpuCPU model, cores and features.
free -hMemory and swap usage.
df -hDisk usage per filesystem.
lsblk -fBlock devices, filesystems and mount points.
lspciPCI devices (GPU, network cards and so on).
lsusbUSB devices.
sudo dmidecode -t memoryInstalled RAM modules and speeds.
journalctl -b -p errErrors logged since this boot.
dmesg --ctime | tail -30The latest kernel messages (may need sudo).
sensorsTemperatures and fan speeds (package lm-sensors).
Files & text
ls -lahList all files with human-readable sizes.
find . -type f -size +100MFiles larger than 100 MB under this folder.
find / -name "*.conf" 2>/dev/nullSearch by name, hiding permission errors.
du -sh * | sort -hSize of each item here, smallest to largest.
grep -rn "text" .Recursive text search with line numbers.
tail -f /var/log/syslogFollow a log file live (Debian/Ubuntu).
cp -a src/ dst/Copy while preserving permissions and links.
rsync -avh --progress src/ user@host:/dst/Efficient copy and sync over SSH.
tar -czvf backup.tar.gz dir/Create a gzip-compressed archive.
tar -xzvf backup.tar.gzExtract a gzip-compressed archive.
zip -r archive.zip dir/Zip a directory (unzip archive.zip extracts it).
chmod 640 fileOwner read/write, group read, others nothing.
chown user:group fileChange a file's owner and group.
ln -s /path/to/target linknameCreate a symbolic link.
stat fileDetailed file metadata and timestamps.
sha256sum file.isoCompute a file checksum.
diff -u a.txt b.txtUnified diff of two files.
sed -i 's/old/new/g' fileReplace text in a file in place.
awk '{print $1}' filePrint the first column of each line.
sort file | uniq -c | sort -nrCount duplicate lines, most frequent first.
watch -n 2 df -hRe-run a command every 2 seconds.
Processes & services (systemd)
ps aux --sort=-%cpu | headTop CPU consumers.
htopInteractive process viewer (install the htop package).
kill PIDAsk a process to exit (SIGTERM). Use kill -9 PID only as a last resort.
pkill -f nameSignal processes matching a name pattern.
systemctl status nginxService state and its recent log lines.
sudo systemctl restart nginxRestart a service.
sudo systemctl enable --now nginxStart a service now and at every boot.
systemctl list-units --failedShow failed units.
journalctl -u nginx -fFollow one service's logs.
sudo systemctl daemon-reloadReload unit files after editing them.
systemctl list-timersScheduled systemd timers.
crontab -eEdit your cron jobs.
Networking
ip -br addrInterfaces and addresses in brief form.
ip routeShow the routing table.
sudo ss -tulpnListening TCP/UDP ports with the owning process.
ping -c 4 example.comFour-packet connectivity test.
mtr example.comLive traceroute with packet loss (install mtr).
dig example.com +shortDNS lookup (package dnsutils or bind-utils).
curl -I https://example.comFetch only the response headers.
wget -c https://example.com/file.isoDownload, resuming if interrupted.
nmcli device statusNetworkManager device states.
resolvectl statusDNS settings (systemd-resolved).
nc -zv example.com 443Test whether a TCP port is open.
sudo tcpdump -i eth0 port 80Capture traffic on port 80.
ssh -p 2222 user@hostConnect over SSH on a non-default port.
ssh-keygen -t ed25519 -C "comment"Create an SSH key pair.
scp -P 2222 file user@host:~/Copy a file over SSH (note the capital -P for the port).
sudo iptables -SList firewall rules as commands.
sudo ufw status verboseUFW firewall status (where UFW is used).
Packages
sudo apt update && sudo apt upgradeUpdate package lists and upgrade (Debian/Ubuntu).
apt search keywordSearch for packages.
sudo apt install packageInstall a package.
sudo apt autoremoveRemove dependencies nobody needs anymore.
apt list --upgradableShow what would be upgraded.
dpkg -l | grep nameCheck whether a package is installed.
sudo dnf upgradeUpgrade packages (Fedora/RHEL family).
dnf search keywordSearch for packages (Fedora/RHEL family).
rpm -qa | grep nameCheck installed RPM packages.
sudo pacman -SyuSync and upgrade everything (Arch).
pacman -Ss keywordSearch packages (Arch).
flatpak updateUpdate Flatpak apps.
snap listInstalled snap packages.
Users & security
idYour UID, GID and groups.
sudo -lWhat sudo lets you run.
whoWho is logged in now.
last -n 10The 10 most recent logins.
sudo adduser nameCreate a user (Debian/Ubuntu).
sudo usermod -aG docker $USERAdd yourself to a group (log out and in afterwards).
sudo visudoEdit the sudoers file safely.
sudo fail2ban-client status sshdStatus of the fail2ban SSH jail.
sudo journalctl -u ssh -n 50Last 50 SSH log lines (the unit is sshd on some distros).
chage -l userShow password aging for a user.
passwdChange your password.
Disks & storage
sudo fdisk -lPartition tables of all disks.
findmntMounted filesystems as a tree.
df -iInode usage per filesystem.
sudo smartctl -a /dev/sdaDisk SMART health (package smartmontools).
swapon --showActive swap devices and usage.
sudo mount /dev/sdb1 /mntMount a partition.
sudo growpart /dev/sda 1Grow partition 1 to fill the disk (package cloud-guest-utils).
sudo resize2fs /dev/sda1Grow an ext4 filesystem to fill its partition.
Docker
docker ps -aAll containers, running or stopped.
docker logs -f --tail 100 nameFollow a container's last 100 log lines.
docker exec -it name shOpen a shell inside a running container.
docker compose up -dStart the compose stack in the background.
docker compose downStop and remove the compose stack.
docker compose pull && docker compose up -dPull newer images and restart.
docker statsLive CPU and memory per container.
docker system dfDisk space used by Docker.
docker system pruneRemove unused containers, networks and images (asks first).
Shell tips
history | grep sshSearch your command history.
Ctrl+RReverse-search your history as you type.
sudo !!Re-run the previous command with sudo.
command > out.txt 2>&1Send stdout and stderr to a file.
cmd1 && cmd2Run cmd2 only if cmd1 succeeded.
man -k keywordSearch man pages by keyword (same as apropos).
tmux new -s mainStart a named tmux session (tmux attach -t main reattaches).
alias ll='ls -lah'Create a shortcut (put it in ~/.bashrc to keep it).