The essential-commands guide is the short list — the few dozen commands you use every day. This is the long list: a categorised reference of the standard command-line tools on Unix-like systems (Linux, the BSDs, macOS) and on Windows (both the legacy Command Prompt and modern PowerShell). You will not memorise all of these. The point of a reference is the opposite of memorising: you skim it once so you know a tool exists, then come back and copy the example when you need it.
How to read this guide:
- Each section is a table: the command, what it does, and a copy-paste example.
- Sections 1–17 are the Unix world (Linux/BSD/macOS). Sections 18–20 cover Windows.
- Most Unix tools here are part of POSIX or the GNU coreutils / util-linux packages shipped by every distribution. A handful (
htop,tree,zstd,rg,nmcli,tldr) are popular add-ons you may need to install — they are marked (install). - Anything in
<angle-brackets>is a placeholder you substitute. Commands needing root are shown withsudo.
1. Navigating the filesystem
Where am I, what is here, and how do I move around.
| Command | What it does | Example |
|---|---|---|
pwd |
Print the current (working) directory. | pwd |
cd |
Change directory. No argument goes home; - goes back. |
cd /etc · cd ~ · cd - |
ls |
List directory contents. | ls -lah |
dir / vdir |
GNU aliases for ls with preset formats. |
vdir |
tree (install) |
Show the directory hierarchy as an indented tree. | tree -L 2 |
pushd / popd |
Change directory but remember the old one on a stack. | pushd /tmp · popd |
dircolors |
Set up the LS_COLORS used by ls --color. |
eval "$(dircolors -b)" |
2. Files and directories
Create, copy, move, delete, link, and inspect files. Handle rm with respect: there is no recycle bin.
| Command | What it does | Example |
|---|---|---|
cp |
Copy files or directories (-r for directories). |
cp -r src/ dst/ |
mv |
Move or rename. | mv old.txt new.txt |
rm |
Delete files (-r recursive, -i ask first). |
rm -i file.txt |
mkdir |
Make directories (-p makes parents). |
mkdir -p a/b/c |
rmdir |
Remove empty directories. | rmdir olddir |
touch |
Create an empty file or update its timestamp. | touch file.txt |
ln |
Make links: -s for a symbolic link. |
ln -s /opt/app/bin app |
readlink |
Show where a symlink points. | readlink -f ./app |
realpath |
Resolve a path to its absolute, canonical form. | realpath ../x |
basename / dirname |
Strip the directory / strip the filename from a path. | basename /a/b.txt |
stat |
Show full metadata: size, owner, timestamps, inode. | stat file.txt |
file |
Identify a file’s type by content, not name. | file mystery.bin |
mktemp |
Create a uniquely-named temp file or directory safely. | mktemp -d |
install |
Copy files and set mode/owner in one step. | install -m 755 x /usr/local/bin |
shred |
Overwrite a file so it is hard to recover, then delete. | shred -u secret.key |
truncate |
Shrink or extend a file to an exact size. | truncate -s 0 log.txt |
rename |
Bulk-rename via a pattern (Perl rename on many distros). |
rename 's/.txt$/.md/' *.txt |
mkfifo |
Create a named pipe (FIFO) for inter-process streams. | mkfifo mypipe |
3. Viewing and dissecting file content
Read files whole, page through them, peek at the ends, or crack them open byte by byte.
| Command | What it does | Example |
|---|---|---|
cat | Concatenate / dump a file to the screen. | cat file.txt |
tac | Like cat but bottom-to-top (reversed lines). | tac file.txt |
less / more | Page through a file (q quits, / searches). | less /var/log/syslog |
head / tail | First / last N lines. tail -f follows a growing file. | tail -f app.log |
nl | Number the lines of a file. | nl script.sh |
tee | Copy stdin to a file and to the screen. | make 2>&1 | tee build.log |
od | Octal/hex dump of raw bytes. | od -c file.bin |
hexdump / xxd | Hex view of a file (and back, with xxd -r). | xxd file.bin | head |
strings | Pull printable text out of a binary. | strings /bin/ls | less |
split / csplit | Split a file into pieces by size/lines or by pattern. | split -b 10M big.iso part_ |
fold | Wrap long lines to a fixed width. | fold -w 72 essay.txt |
fmt / pr | Reformat / paginate text for reading or printing. | fmt -w 80 notes.txt |
4. Finding things
Locate files by name or attribute, and search inside them. For the deep dive on find, xargs, and safely handling odd filenames, see the find, xargs, and the -print0 dance guide.
| Command | What it does | Example |
|---|---|---|
find |
Walk a directory tree filtering by name, type, age, size… | find . -name "*.log" -mtime -7 |
locate / updatedb |
Instant name search from a prebuilt index; refresh with updatedb. |
locate sshd_config |
which |
Show the path of the executable that would run. | which python3 |
whereis |
Locate the binary, source, and man page for a command. | whereis ls |
type |
Is it a builtin, alias, function, or binary? | type cd |
grep |
Search inside files for lines matching a pattern. | grep -rin "error" . |
rg (install) |
ripgrep: a much faster, gitignore-aware recursive grep. | rg "TODO" |
5. Processing and transforming text
The heart of the Unix philosophy: small tools that filter streams. For the two big ones, see awk in ten minutes and sed in ten minutes.
| Command | What it does | Example |
|---|---|---|
awk | Field-oriented mini-language for columns and reports. | awk -F, '{print $2}' data.csv |
sed | Stream editor: substitute, delete, insert by pattern. | sed 's/old/new/g' file |
cut | Extract columns by delimiter or character position. | cut -d: -f1 /etc/passwd |
paste | Merge lines of files side by side. | paste names.txt ages.txt |
join | Relational join of two sorted files on a key. | join a.txt b.txt |
sort | Sort lines (-n numeric, -h human sizes, -r reverse). | du -sh * | sort -h |
uniq | Collapse or count adjacent duplicate lines. | sort f | uniq -c |
comm | Compare two sorted files line by line (common/unique). | comm -23 a.txt b.txt |
tr | Translate or delete characters. | tr a-z A-Z < file |
wc | Count lines, words, and bytes. | wc -l file.txt |
expand / unexpand | Convert tabs to spaces and back. | expand -t4 code.py |
column | Format input into neat aligned columns. | column -t -s, data.csv |
diff / diff3 | Show differences between two (or three) files. | diff -u old new |
cmp | Byte-for-byte comparison; reports the first difference. | cmp a.bin b.bin |
patch | Apply a diff/patch to files. | patch -p1 < fix.patch |
rev | Reverse the characters of each line. | echo abc | rev |
expr | Evaluate a simple arithmetic/string expression. | expr 3 + 4 |
seq | Print a sequence of numbers. | seq 1 10 |
shuf | Shuffle lines / pick a random selection. | shuf -n1 names.txt |
numfmt | Convert numbers to/from human-readable units. | numfmt --to=iec 1048576 |
printf | Formatted output (more predictable than echo). | printf '%s=%d
' x 5 |
yes | Repeat a string forever (to feed prompts). | yes | rm -ri junk/ |
6. Archives and compression
Bundle directories and squeeze them. Remember tar’s flags: create, extract, t=list, file, z=gzip, j=bzip2, J=xz.
| Command | What it does | Example |
|---|---|---|
tar | Create/extract archives, optionally compressed. | tar -czf out.tgz dir/ |
gzip / gunzip / zcat | Compress / decompress / view a single .gz file. | gzip -k big.log |
bzip2 / bunzip2 | Slower but tighter compression than gzip. | bzip2 dump.sql |
xz / unxz | Very high compression ratio (slow). | xz -9 archive.tar |
zstd (install) | Modern compressor: near-gzip ratio at very high speed. | zstd -19 file |
zip / unzip | Windows-compatible zip archives. | zip -r site.zip site/ |
cpio | Old-school archiver, still used by initramfs/RPM. | find . | cpio -o > a.cpio |
ar | Create/extract .a static-library and .deb archives. | ar t libfoo.a |
dd | Block-level copy: images, disks, exact byte transfers. | sudo dd if=img.iso of=/dev/sdX bs=4M status=progress |
7. Permissions and ownership
Who can read, write, and execute what. For the full mental model (including the sticky bit and setgid), see permissions, ownership, and the sticky bit.
| Command | What it does | Example |
|---|---|---|
chmod |
Change permission bits (symbolic or numeric). | chmod 755 script.sh |
chown |
Change the owning user (and group). | sudo chown alice:staff f |
chgrp |
Change only the owning group. | sudo chgrp wheel f |
umask |
Show/set default permissions for new files. | umask 022 |
getfacl / setfacl |
Read/write fine-grained POSIX access control lists. | setfacl -m u:bob:rw f |
chattr / lsattr |
Set/list extended ext-fs attributes (e.g. immutable). | sudo chattr +i important |
8. Users, groups, and identity
Who you are, who else is here, and how to become someone else. For account management end to end, see users, groups, and sudo.
| Command | What it does | Example |
|---|---|---|
whoami |
Print your current username. | whoami |
id |
Show your UID, GID, and group memberships. | id |
groups |
List the groups you belong to. | groups |
who / w |
Who is logged in (and what they are doing). | w |
last |
Show recent login history. | last -10 |
su |
Switch to another user (root by default). | su - alice |
sudo |
Run a single command as root (or another user). | sudo systemctl restart sshd |
passwd |
Change a password. | passwd |
useradd / usermod / userdel |
Create / modify / delete user accounts. | sudo useradd -m bob |
groupadd / newgrp |
Create a group / switch your active group. | sudo groupadd devs |
chsh / chfn |
Change your login shell / your contact (GECOS) info. | chsh -s /bin/zsh |
9. Processes and jobs
See what is running, control it, and keep it alive. Deeper material in processes and system monitoring.
| Command | What it does | Example |
|---|---|---|
ps |
Snapshot of running processes. | ps aux |
top |
Live, updating process viewer. | top |
htop (install) |
Friendlier, colourful interactive top. |
htop |
pgrep / pidof |
Find process IDs by name. | pgrep -f nginx |
kill |
Send a signal to a PID (default: ask it to quit). | kill -9 1234 |
pkill / killall |
Signal processes by name. | pkill firefox |
nice / renice |
Start / change a process’s scheduling priority. | nice -n 19 backup.sh |
nohup |
Run a command that survives logout. | nohup ./worker & |
jobs / fg / bg |
List / foreground / background shell jobs. | jobs · fg %1 |
disown |
Detach a job from the shell so it survives exit. | disown -h %1 |
wait |
Block until background jobs finish. | wait |
time |
Measure how long a command takes. | time make |
timeout |
Kill a command if it runs too long. | timeout 30 ./slow |
watch |
Re-run a command every N seconds. | watch -n1 df -h |
fuser / lsof |
Find which process holds a file/port open. | sudo lsof -i :443 |
strace (install) |
Trace the system calls a process makes. | strace -f ./app |
10. System information and hardware
Facts about the machine: kernel, CPU, memory, disks, devices.
| Command | What it does | Example |
|---|---|---|
uname | Kernel name, version, and architecture. | uname -a |
hostname | Show or set the machine’s name. | hostname |
uptime | How long up, plus load average. | uptime |
date / cal | Current date/time / a calendar. | date +%F · cal |
df | Free space per mounted filesystem. | df -h |
du | Disk used by files/directories. | du -sh * |
free | Memory and swap usage (Linux). | free -h |
vmstat / iostat | Live virtual-memory / IO statistics. | vmstat 1 |
lscpu | CPU model, cores, cache, flags. | lscpu |
lsblk | Tree of block devices and partitions. | lsblk -f |
lsusb / lspci | List USB / PCI devices. | lspci | grep -i vga |
dmidecode | Read hardware details from the BIOS/SMBIOS. | sudo dmidecode -t memory |
sysctl | Read/set kernel parameters at runtime. | sysctl vm.swappiness |
dmesg | Kernel ring-buffer messages (boot, hardware, drivers). | dmesg -w |
lsmod | List loaded kernel modules. | lsmod | grep snd |
env / printenv | Show the environment variables. | printenv PATH |
11. Disks, partitions, and filesystems
Partition, format, mount, and check storage. Mistakes here can erase data — double-check the device name. See disks: lsblk, fdisk, mkfs, fstab, UUIDs and filesystems explained.
| Command | What it does | Example |
|---|---|---|
mount / umount |
Attach / detach a filesystem. | sudo mount /dev/sdb1 /mnt |
fdisk / parted |
Create and edit a partition table. | sudo fdisk -l |
mkfs |
Create (format) a filesystem. | sudo mkfs.ext4 /dev/sdb1 |
fsck |
Check and repair a filesystem (unmounted). | sudo fsck /dev/sdb1 |
blkid |
Show UUIDs and types of block devices. | blkid |
sync |
Flush pending disk writes to hardware. | sync |
swapon / swapoff |
Enable / disable swap space. | sudo swapon -a |
tune2fs |
Tune ext2/3/4 parameters (labels, reserved blocks). | sudo tune2fs -l /dev/sda1 |
badblocks |
Scan a device for bad sectors. | sudo badblocks -sv /dev/sdb |
12. Networking
Reach other machines, move files, and inspect connections. See networking basics, SSH the boring way, and rsync without losing data.
| Command | What it does | Example |
|---|---|---|
ping |
Is a host reachable? Measure round-trip time. | ping -c4 example.com |
curl |
Transfer data to/from URLs (HTTP, FTP, …). | curl -L https://x.test |
wget |
Download files (good at resuming/mirroring). | wget -c big.iso |
ssh |
Secure shell into another machine. | ssh user@host |
scp / sftp |
Copy files over SSH. | scp f user@host:/tmp/ |
rsync |
Efficient incremental file sync (local or remote). | rsync -avz src/ host:/dst/ |
nc (netcat) |
Raw TCP/UDP: test ports, move data, simple servers. | nc -vz host 22 |
ip |
Modern Linux net config: addresses, routes, links. | ip addr |
ifconfig |
Legacy interface config (still default on BSD/macOS). | ifconfig |
ss / netstat |
List sockets and connections. | ss -tulpn |
traceroute / tracepath |
Show the network hops to a host. | traceroute example.com |
dig / host / nslookup |
Query DNS. | dig +short example.com |
arp |
Show the ARP table (IP↔MAC mapping). | arp -a |
tcpdump |
Capture and inspect network packets. | sudo tcpdump -i any port 53 |
nmcli (install) |
Control NetworkManager from the terminal. | nmcli device wifi list |
13. Shell builtins and control flow
These are part of the shell itself (bash/zsh), not separate programs — which is why man cd fails but help cd works.
| Command | What it does | Example |
|---|---|---|
echo | Print arguments to stdout. | echo "hi" |
export | Mark a variable for the environment of child processes. | export PATH="$PATH:~/bin" |
alias / unalias | Make / remove a command shortcut. | alias ll='ls -lah' |
source / . | Run a script in the current shell (keeps its vars). | source ~/.bashrc |
exec | Replace the shell with another program. | exec bash |
eval | Evaluate a string as a command. | eval "$(ssh-agent)" |
set / unset | Set shell options / variables, or remove variables. | set -euo pipefail |
read | Read a line of input into variables. | read -p "Name: " n |
test / [ | Evaluate a condition (files, strings, numbers). | [ -f file ] && echo yes |
true / false | Do nothing, succeed / fail (for loops and defaults). | while true; do :; done |
history | Show or search your command history. | history | grep ssh |
trap | Run code on a signal or on exit. | trap cleanup EXIT |
exit | Leave the shell with a status code. | exit 0 |
command / hash / ulimit | Bypass aliases / cache lookups / set resource limits. | ulimit -n 4096 |
getopts | Parse option flags inside a shell script. | while getopts ":v" o; do ... |
14. Scheduling and services
Run things later, on a schedule, or as managed background services. See cron and systemd timers.
| Command | What it does | Example |
|---|---|---|
crontab | Edit/list your scheduled (cron) jobs. | crontab -e |
at / atq / atrm | Run a command once at a future time; list/remove. | echo "reboot" | at 2am |
batch | Run a job when system load is low. | batch < job.sh |
sleep | Pause for a duration. | sleep 5 |
systemctl | Manage systemd services (start/stop/enable/status). | systemctl status sshd |
journalctl | Query the systemd journal (logs). | journalctl -u nginx -f |
service | Legacy/portable wrapper to start/stop services. | sudo service cron restart |
15. Terminal and session control
Tidy and reconfigure the terminal itself — including clear, the everyday command missing from the short guide.
| Command | What it does | Example |
|---|---|---|
clear |
Clear the screen (same as Ctrl+L). | clear |
reset |
Fully reinitialise a terminal mangled by binary output. | reset |
tput |
Query/set terminal capabilities (colours, cursor). | tput cols |
stty |
Show/change terminal line settings. | stty -echo |
tty |
Print the terminal device you are attached to. | tty |
script |
Record everything in a session to a file. | script session.log |
setterm |
Set terminal attributes (blanking, bold, colour). | setterm --blank 0 |
locale |
Show/set language and character-encoding settings. | locale |
tmux / screen (install) |
Terminal multiplexer: persistent, splittable sessions. | tmux new -s work |
For the full multiplexer workflow, see tmux in twenty minutes.
16. Maths, encoding, and miscellany
Calculators, hashes, encoders, and the odd-but-useful utilities.
| Command | What it does | Example |
|---|---|---|
bc / dc | Arbitrary-precision calculators (infix / RPN). | echo "2^10" | bc |
units | Convert between units of measure. | units "10 mi" km |
xargs | Build and run commands from input items. | find . -name "*.bak" | xargs rm |
env | Run a command with a modified environment. | env FOO=1 ./app |
base64 / base32 | Encode/decode binary as text. | base64 file > file.b64 |
md5sum / sha256sum | Compute/verify file checksums. | sha256sum download.iso |
cksum | CRC checksum and byte count. | cksum file |
uuidgen | Generate a random UUID. | uuidgen |
gpg | Encrypt, decrypt, and sign with OpenPGP. | gpg -c secret.txt |
openssl | Swiss-army crypto: keys, certs, hashes, TLS tests. | openssl rand -hex 16 |
flock | Take a lock so two scripts do not run at once. | flock /tmp/x.lock cmd |
17. Getting help
The terminal documents itself. Learn these and you can teach yourself the rest.
| Command | What it does | Example |
|---|---|---|
man |
The manual page for a command. | man tar |
info |
GNU’s longer, hyperlinked manuals. | info coreutils |
apropos / whatis |
Search man pages by keyword / one-line summary. | apropos copy |
help |
Documentation for shell builtins. | help cd |
tldr (install) |
Community cheat-sheets: just the common examples. | tldr tar |
<cmd> --help |
Most commands print a short usage summary. | ls --help |
18. Windows: Command Prompt (CMD)
Everything above assumes a Unix-like shell. Windows ships its own command line. The legacy Command Prompt (cmd.exe) uses a different command set; commands and flags are case-insensitive and use /flag rather than -flag.
| Command | What it does | Example |
|---|---|---|
dir | List directory contents (like ls). | dir /a |
cd / chdir | Change / print the current directory. | cd Users |
copy / xcopy / robocopy | Copy files; robocopy is the robust mirroring tool. | robocopy src dst /MIR |
move | Move or rename files. | move a.txt b.txt |
del / erase | Delete files. | del *.tmp |
ren / rename | Rename a file. | ren a.txt b.txt |
md / rd | Make / remove a directory. | md newdir |
type | Print a file (like cat). | type notes.txt |
more | Page through output. | type big.log | more |
cls | Clear the screen (the CMD clear). | cls |
find / findstr | Search text in files (findstr supports regex). | findstr /s "TODO" *.cs |
tree | Show the directory tree. | tree /f |
attrib | Show/change file attributes (read-only, hidden). | attrib +r file.txt |
fc / comp | Compare two files. | fc a.txt b.txt |
where | Locate an executable (like which). | where python |
set | Show/set environment variables. | set PATH |
tasklist / taskkill | List / kill processes. | taskkill /IM notepad.exe /F |
sc / net | Manage Windows services and shares. | net start spooler |
systeminfo / ver | OS, hardware summary / just the version. | systeminfo |
hostname | Show the computer name. | hostname |
ipconfig | Show/refresh IP configuration. | ipconfig /all |
ping / tracert / pathping | Reachability / route / route+loss to a host. | tracert example.com |
nslookup | Query DNS. | nslookup example.com |
netstat / route / arp | Connections / routing table / ARP cache. | netstat -ano |
getmac | Show network adapter MAC addresses. | getmac |
sfc / chkdsk | Check/repair system files / a disk. | sfc /scannow |
diskpart | Interactive disk and partition management. | diskpart |
format / label / vol | Format a drive / set / show its volume label. | format D: /FS:NTFS |
assoc / ftype | Map file extensions to programs. | assoc .txt |
shutdown | Shut down or restart the machine. | shutdown /r /t 0 |
echo / date / time | Print text / show-set date / show-set time. | echo Hello |
help | List built-in commands or help for one. | help dir |
19. Windows: PowerShell
Modern Windows (and cross-platform PowerShell 7) uses a richer shell built on objects, not text. Commands are cmdlets named Verb-Noun, but most have short aliases — several deliberately match Unix names. Below, each row notes the built-in alias in parentheses.
| Cmdlet (alias) | What it does | Example |
|---|---|---|
Get-ChildItem (ls, dir) | List items in a directory. | Get-ChildItem -Recurse |
Set-Location (cd) | Change directory. | Set-Location C: |
Get-Location (pwd) | Print the current directory. | Get-Location |
Copy-Item (cp) | Copy files or directories. | Copy-Item a.txt b.txt |
Move-Item (mv) | Move or rename. | Move-Item a.txt b.txt |
Remove-Item (rm, del) | Delete files or directories. | Remove-Item -Recurse old |
New-Item | Create a file or directory. | New-Item -ItemType Directory d |
Get-Content (cat, type) | Read a file’s contents. | Get-Content log.txt -Tail 20 |
Set-Content / Add-Content | Write / append to a file. | Set-Content f.txt "hi" |
Select-String (sls) | Search text (like grep). | Select-String "error" *.log |
Get-Process (ps) | List running processes. | Get-Process | Sort CPU |
Stop-Process (kill) | Kill a process. | Stop-Process -Name notepad |
Get-Service / Start-Service / Stop-Service | Manage Windows services. | Get-Service | Where Status -eq Running |
Test-Connection | Ping a host (object output). | Test-Connection example.com |
Invoke-WebRequest (curl, wget) | Fetch a URL / download a file. | Invoke-WebRequest -Uri $u -OutFile f |
Where-Object / ForEach-Object | Filter / iterate the object pipeline. | Get-Process | Where CPU -gt 10 |
Select-Object / Sort-Object / Measure-Object | Pick columns / sort / count & sum. | ... | Sort-Object Name |
Get-Command / Get-Help (man) | Discover cmdlets / read their help. | Get-Help Get-ChildItem -Examples |
Clear-Host (cls, clear) | Clear the screen. | Clear-Host |
Set-ExecutionPolicy | Control whether scripts may run. | Set-ExecutionPolicy RemoteSigned |
20. Unix → Windows quick translation
If you know the Unix command, here is the everyday Windows equivalent in each shell. Exact flags differ — this is for “what is this called over there?”
| Unix | CMD | PowerShell |
|---|---|---|
ls |
dir |
Get-ChildItem |
cd (alone) |
cd |
Get-Location |
pwd |
cd |
Get-Location |
cp |
copy / robocopy |
Copy-Item |
mv |
move |
Move-Item |
rm |
del / rd |
Remove-Item |
mkdir |
md |
New-Item -ItemType Directory |
cat |
type |
Get-Content |
grep |
findstr |
Select-String |
clear |
cls |
Clear-Host |
man |
help <cmd> / <cmd> /? |
Get-Help |
which |
where |
Get-Command |
ps |
tasklist |
Get-Process |
kill |
taskkill |
Stop-Process |
ifconfig / ip |
ipconfig |
Get-NetIPConfiguration |
netstat |
netstat |
Get-NetTCPConnection |
curl / wget |
curl (Win10+) |
Invoke-WebRequest |
df |
wmic logicaldisk |
Get-PSDrive |
chmod |
icacls |
icacls / Set-Acl |
top |
tasklist |
Get-Process |
env |
set |
Get-ChildItem Env: |
shutdown -r |
shutdown /r |
Restart-Computer |
The honest truth, again
This is a long list, and nobody holds it all in their head. The win is recognition, not recall: once you know a job has a tool — “there is a command that mirrors a directory tree”, “there is one that follows a log” — you can find the exact name and flags here or in man in under a minute. Start with the essential-commands short list, keep this page bookmarked, and grow your toolkit one remembered name at a time.