Copy, paste, done

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

systeminfo

Detailed OS, hardware and hotfix summary.

CMD
Get-ComputerInfo

OS, BIOS and hardware properties as objects.

PowerShell
winver

Show the Windows version and build in a dialog.

CMD
hostname

Print the computer name.

CMD
Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Version, LastBootUpTime

OS name, build and last boot time.

PowerShell
Get-CimInstance Win32_Processor | Select-Object Name, NumberOfCores, NumberOfLogicalProcessors

CPU model and core counts.

PowerShell
Get-Volume

Drives with file system, size and free space.

PowerShell
Get-PhysicalDisk

Physical disks with health status and media type.

PowerShell
msinfo32

Open the System Information console.

CMD
devmgmt.msc

Open Device Manager.

CMD
diskmgmt.msc

Open Disk Management.

CMD

Processes, services & tasks

Get-Process | Sort-Object CPU -Descending | Select-Object -First 10

Top 10 processes by CPU time.

PowerShell
tasklist

List running processes.

CMD
taskkill /PID 1234 /F

Force-stop a process by its ID.

CMD
Stop-Process -Name notepad -Force

Stop processes by name.

PowerShell
Get-Service | Where-Object Status -eq Running

Show running services.

PowerShell
Restart-Service -Name Spooler

Restart a service (example: Print Spooler).

PowerShellrun as admin
sc query state= all

List all services and their state.

CMD
services.msc

Open the Services console.

CMD
taskschd.msc

Open Task Scheduler.

CMD
schtasks /query /fo LIST

List scheduled tasks.

CMD
Get-WinEvent -LogName System -MaxEvents 20

The 20 most recent System log events.

PowerShell
Get-WinEvent -FilterHashtable @{LogName='System'; Level=2; StartTime=(Get-Date).AddDays(-1)}

System errors from the last 24 hours.

PowerShell

Networking

ipconfig /all

Full IP configuration for every adapter.

CMD
ipconfig /flushdns

Clear the DNS resolver cache.

CMD
ipconfig /release && ipconfig /renew

Drop and renew the DHCP lease.

CMDrun as admin
ping -n 4 8.8.8.8

Test connectivity with four packets.

CMD
tracert example.com

Show the route to a host.

CMD
pathping example.com

Ping plus per-hop packet loss.

CMD
nslookup example.com

Query DNS.

CMD
Resolve-DnsName example.com -Type A

DNS query in PowerShell.

PowerShell
Test-NetConnection example.com -Port 443

Test whether a TCP port is reachable.

PowerShell
netstat -ano

Connections and listening ports with the owning process ID.

CMD
Get-NetTCPConnection -State Listen

Listening TCP ports.

PowerShell
Get-NetAdapter

Network adapters, status and link speed.

PowerShell
Get-NetIPAddress -AddressFamily IPv4

All IPv4 addresses.

PowerShell
netsh wlan show profiles

Saved Wi-Fi networks.

CMD
netsh winsock reset

Reset the Winsock catalog (reboot afterwards).

CMDrun as admin
netsh advfirewall show allprofiles

Windows Firewall state per profile.

CMD
arp -a

Show the ARP table.

CMD
route print

Show the routing table.

CMD

Disk, files & repair

sfc /scannow

Scan and repair protected system files.

CMDrun as admin
DISM /Online /Cleanup-Image /RestoreHealth

Repair the component store (run before sfc if sfc fails).

CMDrun as admin
chkdsk C: /scan

Online scan of a volume for errors.

CMDrun as admin
cleanmgr

Open Disk Cleanup.

CMD
fsutil volume diskfree C:

Free and total space on a volume.

CMDrun as admin
Get-FileHash .\file.iso -Algorithm SHA256

Compute a file checksum.

PowerShell
certutil -hashfile file.iso SHA256

Compute a checksum from CMD.

CMD
Get-ChildItem C:\ -Recurse -File -ErrorAction SilentlyContinue | Sort-Object Length -Descending | Select-Object -First 20 FullName, Length

20 largest files on C: (slow on big disks).

PowerShell
robocopy C:\src D:\dst /MIR /R:2 /W:2

Mirror a folder. Deletes extra files at the destination, so double-check the paths.

CMDcareful
mklink /D Link Target

Create a directory symbolic link.

CMDrun as admin

Users & security

whoami /all

Current user, SID, groups and privileges.

CMD
net user

List local user accounts.

CMD
net localgroup administrators

Members of the local Administrators group.

CMD
Get-LocalUser

Local accounts and whether they are enabled.

PowerShell
gpupdate /force

Refresh Group Policy now.

CMD
gpresult /r

Summary of applied Group Policy.

CMD
Get-MpComputerStatus

Microsoft Defender status and signature age.

PowerShell
Start-MpScan -ScanType QuickScan

Run a Defender quick scan.

PowerShell
manage-bde -status

BitLocker status for each drive.

CMDrun as admin

Updates, packages & power

winget upgrade

List available app upgrades.

CMD
winget upgrade --all

Upgrade everything winget can.

CMD
winget search vlc

Search for a package.

CMD
winget install VideoLAN.VLC

Install a package by ID.

CMD
Get-HotFix

Installed Windows updates (hotfixes).

PowerShell
powercfg /batteryreport

Write a battery health report (HTML) to the current folder.

CMD
powercfg /energy

60-second energy-efficiency diagnostics report.

CMDrun as admin
shutdown /r /t 0

Restart immediately.

CMD
shutdown /s /t 0

Shut down immediately.

CMD
shutdown /a

Abort a pending shutdown.

CMD

PowerShell basics & WSL

Get-Help Get-Process -Examples

Show examples for a cmdlet.

PowerShell
Get-Command *service*

Find commands by name.

PowerShell
Get-ExecutionPolicy -List

Show the script execution policy at each scope.

PowerShell
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Allow local scripts for your user only.

PowerShell
Get-History | Select-Object -Last 20

Your 20 most recent commands.

PowerShell
wsl --list --verbose

Installed distributions and their WSL version.

CMD
wsl --install

Install WSL with the default distribution.

CMDrun as admin
wsl --update

Update the WSL kernel.

CMD
wsl --shutdown

Stop all running WSL distributions.

CMD

Linux 113 commands

System & hardware

uname -a

Kernel version and architecture.

cat /etc/os-release

Distribution name and version.

hostnamectl

Hostname, OS, kernel and machine information.

uptime

Time since boot and load averages.

lscpu

CPU model, cores and features.

free -h

Memory and swap usage.

df -h

Disk usage per filesystem.

lsblk -f

Block devices, filesystems and mount points.

lspci

PCI devices (GPU, network cards and so on).

lsusb

USB devices.

sudo dmidecode -t memory

Installed RAM modules and speeds.

needs sudo
journalctl -b -p err

Errors logged since this boot.

dmesg --ctime | tail -30

The latest kernel messages (may need sudo).

sensors

Temperatures and fan speeds (package lm-sensors).

Files & text

ls -lah

List all files with human-readable sizes.

find . -type f -size +100M

Files larger than 100 MB under this folder.

find / -name "*.conf" 2>/dev/null

Search by name, hiding permission errors.

du -sh * | sort -h

Size of each item here, smallest to largest.

grep -rn "text" .

Recursive text search with line numbers.

tail -f /var/log/syslog

Follow 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.gz

Extract a gzip-compressed archive.

zip -r archive.zip dir/

Zip a directory (unzip archive.zip extracts it).

chmod 640 file

Owner read/write, group read, others nothing.

chown user:group file

Change a file's owner and group.

needs sudo
ln -s /path/to/target linkname

Create a symbolic link.

stat file

Detailed file metadata and timestamps.

sha256sum file.iso

Compute a file checksum.

diff -u a.txt b.txt

Unified diff of two files.

sed -i 's/old/new/g' file

Replace text in a file in place.

awk '{print $1}' file

Print the first column of each line.

sort file | uniq -c | sort -nr

Count duplicate lines, most frequent first.

watch -n 2 df -h

Re-run a command every 2 seconds.

Processes & services (systemd)

ps aux --sort=-%cpu | head

Top CPU consumers.

htop

Interactive process viewer (install the htop package).

kill PID

Ask a process to exit (SIGTERM). Use kill -9 PID only as a last resort.

pkill -f name

Signal processes matching a name pattern.

systemctl status nginx

Service state and its recent log lines.

sudo systemctl restart nginx

Restart a service.

needs sudo
sudo systemctl enable --now nginx

Start a service now and at every boot.

needs sudo
systemctl list-units --failed

Show failed units.

journalctl -u nginx -f

Follow one service's logs.

sudo systemctl daemon-reload

Reload unit files after editing them.

needs sudo
systemctl list-timers

Scheduled systemd timers.

crontab -e

Edit your cron jobs.

Networking

ip -br addr

Interfaces and addresses in brief form.

ip route

Show the routing table.

sudo ss -tulpn

Listening TCP/UDP ports with the owning process.

needs sudo
ping -c 4 example.com

Four-packet connectivity test.

mtr example.com

Live traceroute with packet loss (install mtr).

dig example.com +short

DNS lookup (package dnsutils or bind-utils).

curl -I https://example.com

Fetch only the response headers.

wget -c https://example.com/file.iso

Download, resuming if interrupted.

nmcli device status

NetworkManager device states.

resolvectl status

DNS settings (systemd-resolved).

nc -zv example.com 443

Test whether a TCP port is open.

sudo tcpdump -i eth0 port 80

Capture traffic on port 80.

needs sudo
ssh -p 2222 user@host

Connect 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 -S

List firewall rules as commands.

needs sudo
sudo ufw status verbose

UFW firewall status (where UFW is used).

needs sudo

Packages

sudo apt update && sudo apt upgrade

Update package lists and upgrade (Debian/Ubuntu).

needs sudo
apt search keyword

Search for packages.

sudo apt install package

Install a package.

needs sudo
sudo apt autoremove

Remove dependencies nobody needs anymore.

needs sudo
apt list --upgradable

Show what would be upgraded.

dpkg -l | grep name

Check whether a package is installed.

sudo dnf upgrade

Upgrade packages (Fedora/RHEL family).

needs sudo
dnf search keyword

Search for packages (Fedora/RHEL family).

rpm -qa | grep name

Check installed RPM packages.

sudo pacman -Syu

Sync and upgrade everything (Arch).

needs sudo
pacman -Ss keyword

Search packages (Arch).

flatpak update

Update Flatpak apps.

snap list

Installed snap packages.

Users & security

id

Your UID, GID and groups.

sudo -l

What sudo lets you run.

needs sudo
who

Who is logged in now.

last -n 10

The 10 most recent logins.

sudo adduser name

Create a user (Debian/Ubuntu).

needs sudo
sudo usermod -aG docker $USER

Add yourself to a group (log out and in afterwards).

needs sudo
sudo visudo

Edit the sudoers file safely.

needs sudo
sudo fail2ban-client status sshd

Status of the fail2ban SSH jail.

needs sudo
sudo journalctl -u ssh -n 50

Last 50 SSH log lines (the unit is sshd on some distros).

needs sudo
chage -l user

Show password aging for a user.

passwd

Change your password.

Disks & storage

sudo fdisk -l

Partition tables of all disks.

needs sudo
findmnt

Mounted filesystems as a tree.

df -i

Inode usage per filesystem.

sudo smartctl -a /dev/sda

Disk SMART health (package smartmontools).

needs sudo
swapon --show

Active swap devices and usage.

sudo mount /dev/sdb1 /mnt

Mount a partition.

needs sudo
sudo growpart /dev/sda 1

Grow partition 1 to fill the disk (package cloud-guest-utils).

needs sudocareful
sudo resize2fs /dev/sda1

Grow an ext4 filesystem to fill its partition.

needs sudo

Docker

docker ps -a

All containers, running or stopped.

docker logs -f --tail 100 name

Follow a container's last 100 log lines.

docker exec -it name sh

Open a shell inside a running container.

docker compose up -d

Start the compose stack in the background.

docker compose down

Stop and remove the compose stack.

docker compose pull && docker compose up -d

Pull newer images and restart.

docker stats

Live CPU and memory per container.

docker system df

Disk space used by Docker.

docker system prune

Remove unused containers, networks and images (asks first).

careful

Shell tips

history | grep ssh

Search your command history.

Ctrl+R

Reverse-search your history as you type.

sudo !!

Re-run the previous command with sudo.

command > out.txt 2>&1

Send stdout and stderr to a file.

cmd1 && cmd2

Run cmd2 only if cmd1 succeeded.

man -k keyword

Search man pages by keyword (same as apropos).

tmux new -s main

Start a named tmux session (tmux attach -t main reattaches).

alias ll='ls -lah'

Create a shortcut (put it in ~/.bashrc to keep it).