Skip to content

LINUX

Last reviewed: 2026-06-16

Purpose: Quick-reference knowledge base for essential Linux commands โ€” file system navigation, file operations, permissions, process management, networking, disk usage, archives, text processing, package management, and system information.


File System Navigation

Command Description Example
pwd Print working directory pwd โ†’ /home/user
ls [opts] [path] List directory contents ls -lah /var/log
cd [dir] Change directory cd ~/Documents
tree [dir] Show directory tree tree -L 2 /etc
realpath [file] Resolve symlink/relative path realpath script.sh
pushd / popd Directory stack navigation pushd /tmp && popd

Common ls flags: -l (long), -a (hidden), -h (human-readable), -t (sort by time), -S (sort by size).


File Operations

Command Description Example
cp [src] [dst] Copy files/directories cp -r backup/ /mnt/disk/
mv [src] [dst] Move or rename mv old.txt new.txt
rm [file] Remove files rm -rf tempdir/
mkdir [dir] Create directory mkdir -p a/b/c
rmdir [dir] Remove empty directory rmdir emptydir/
touch [file] Create empty file / update timestamp touch config.yml
ln -s [target] [link] Create symbolic link ln -s /usr/bin/python3 python
find [path] [expr] Search for files find /home -name '*.log' -size +1M
file [path] Determine file type file /bin/bash
stat [file] Detailed file metadata stat document.pdf

Permissions

Command Description Example
chmod [mode] [file] Change file mode bits chmod 755 script.sh
chown [user][:group] [file] Change owner/group chown paul:admin data.txt
chgrp [group] [file] Change group ownership chgrp www-data index.html
umask [mask] Set default permission mask umask 0022

Permission notation: rwx = 7, rw- = 6, r-x = 5, r-- = 4, -wx = 3, -w- = 2, --x = 1, --- = 0.

Recursive flags: chmod -R, chown -R.

Symbolic mode Equivalent Effect
u+x chmod +x for owner Add execute for owner
g-w โ€” Remove write for group
o=r โ€” Set others to read-only
a+rx chmod +rx Add read+execute for all

Process Management

Command Description Example
ps [opts] Snapshot of current processes ps aux --sort=-%mem
top / htop Interactive process viewer top -u paul
kill [pid] Send signal to process kill -9 1234
pkill [name] Kill by process name pkill -f "python server.py"
pgrep [name] Find PID by name pgrep -u www-data nginx
jobs List background jobs jobs -l
bg / fg Resume job in bg/fg fg %1
nohup [cmd] & Run immune to hup nohup ./server &
systemctl [action] [unit] Systemd service control systemctl restart nginx
journalctl [opts] Query systemd journal journalctl -u sshd -n 50

Common Signals

Signal Number Meaning
SIGHUP 1 Hangup (reload config)
SIGINT 2 Interrupt (Ctrl+C)
SIGKILL 9 Force kill (cannot trap)
SIGTERM 15 Graceful termination

systemctl Actions

Action Effect
start Start a unit
stop Stop a unit
restart Restart a unit
reload Reload config without stopping
enable Start at boot
disable Do not start at boot
status Show unit status
daemon-reload Reload systemd manager config

Networking

Command Description Example
ip addr Show/manipulate network interfaces ip addr show eth0
ip link List/configure network links ip link set eth0 up
ip route Show routing table ip route show default
ss [opts] Socket statistics (modern netstat) ss -tulpn
netstat [opts] Network connections (legacy) netstat -tulpn
curl [url] Transfer data from/to server curl -I https://example.com
wget [url] Non-interactive downloader wget -q -O data.zip url
ping [host] ICMP echo test ping -c 4 google.com
traceroute [host] Trace route to host traceroute 8.8.8.8
nslookup [host] DNS lookup nslookup example.com
dig [host] DNS lookup (verbose) dig +short example.com
ssh [user@host] Secure shell ssh -p 2222 user@10.0.0.5
scp [src] [dst] Secure copy over SSH scp file.txt user@host:/tmp/
ufw [action] Uncomplicated firewall ufw allow 80/tcp

ss / netstat Common Flags

Flag Meaning
-t TCP sockets
-u UDP sockets
-l Listening sockets only
-p Show process/PID
-n Numeric (no name resolution)
-a All sockets (listening + established)

Disk Usage

Command Description Example
df [opts] Filesystem disk space usage df -hT
du [opts] [dir] Directory/file disk usage du -sh /home/paul/*
lsblk [opts] List block devices lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINT
mount [opts] Mount filesystem mount /dev/sdb1 /mnt/data
umount [path] Unmount filesystem umount /mnt/data
blkid Show block device UUIDs/labels blkid /dev/sda1
fdisk [device] Partition table manipulator sudo fdisk -l
parted [device] Partition editor sudo parted /dev/sda print

Common df flags: -h (human-readable), -T (filesystem type), -i (inodes).

Common du flags: -s (summary), -h (human-readable), -a (all files), --max-depth=N.


Archives & Compression

Command Description Example
tar [opts] [archive] [files] Tape archiver tar -czvf archive.tar.gz /path/
tar -xf [archive] Extract tar archive tar -xvf archive.tar.gz -C /target/
gzip [file] Compress file (.gz) gzip file.log
gunzip [file.gz] Decompress .gz gunzip file.log.gz
bzip2 [file] Compress (.bz2, slower/better) bzip2 large.log
xz [file] Compress (.xz, best ratio) xz bigfile.img
zip [out] [in] Zip archive zip -r backup.zip ./data/
unzip [file] Extract zip unzip backup.zip -d ./restore/
zcat [file.gz] Read gzip'd file to stdout zcat log.gz | grep error
zless / zgrep Read/search compressed files zgrep fail messages.gz

tar Operation Flags

Flag Meaning
-c Create archive
-x Extract archive
-t List contents
-v Verbose
-f [file] Archive filename
-z Filter through gzip
-j Filter through bzip2
-J Filter through xz
-C [dir] Change to directory

Text Processing

Command Description Example
cat [file] Concatenate and print files cat file1 file2 > combined
less [file] Paginated file viewer less +F /var/log/syslog
head [-n] [file] First N lines head -20 data.csv
tail [-n] [file] Last N lines tail -f /var/log/nginx/access.log
wc [opts] [file] Word/line/byte count wc -l script.py
sort [opts] [file] Sort lines sort -t, -k2 -n grades.csv
uniq [opts] Remove/report duplicate lines sort words.txt | uniq -c
diff [a] [b] Compare files line by line diff -u old.conf new.conf
cut [opts] Extract columns from lines cut -d: -f1,3 /etc/passwd
tr [set1] [set2] Translate/delete characters echo "HELLO" | tr A-Z a-z
tee [file] Split stdout to file and terminal echo "log" | tee -a log.txt

grep (Global Regular Expression Print)

Usage Description Example
grep [pattern] [file] Search for pattern grep -i "error" /var/log/syslog
-r Recursive directory search grep -r "TODO" ./src/
-v Invert match grep -v "^#" config.conf
-E Extended regex grep -E "(http|https)://" urls.txt
-c Count matches grep -c "failed" auth.log
-l List matching filenames only grep -l "main" *.py
-A[N] / -B[N] After / Before context grep -A2 -B2 "panic" dmesg
-o Show only matched part grep -oP "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}" log

sed (Stream Editor)

Usage Description Example
sed 's/old/new/' Replace first occurrence per line sed 's/foo/bar/' file.txt
sed 's/old/new/g' Replace all occurrences (global) sed 's/old/new/g' file.txt
sed 's/old/new/g' -i In-place edit sed -i 's/Old/New/g' config.yml
sed -n '/pattern/p' Print matching lines sed -n '/ERROR/p' log.txt
sed '/pattern/d' Delete matching lines sed '/^#/d' config.conf
sed '3,5d' Delete lines 3โ€“5 sed '3,5d' file.txt

awk (Pattern Scanning & Processing)

Usage Description Example
awk '{print $1}' Print first field awk '{print $1, $3}' /proc/loadavg
awk -F',' '{print $2}' Custom field separator awk -F: '{print $1}' /etc/passwd
awk '/pattern/' Filter by pattern awk '/404/ {print $7}' access.log
awk '{sum+=$1} END{print sum}' Sum a column awk '{s+=$5} END{print s}' sizes.txt
awk 'NR>1 {print}' Skip header line awk 'NR>1' data.tsv

jq (JSON Query)

Usage Description Example
jq '.' file.json Pretty-print JSON jq '.' data.json
jq '.key' Access key curl api.example.com | jq '.results[0].name'
jq '.[] | select(.status=="active")' Filter array jq '.[] | select(.age > 18)' users.json
jq -r '.key' Raw output (no quotes) jq -r '.ip_address' config.json
jq 'keys' List object keys jq 'keys' package.json
jq 'length' Array/object length jq 'length' data.json

Package Management (apt)

Command Description Example
apt update Update package index sudo apt update
apt upgrade Upgrade all upgradable packages sudo apt upgrade -y
apt full-upgrade Upgrade with dependency changes sudo apt full-upgrade
apt install [pkg] Install package(s) sudo apt install htop neofetch
apt remove [pkg] Remove package (keep config) sudo apt remove nginx
apt purge [pkg] Remove package + config files sudo apt purge nginx
apt autoremove Remove orphaned dependencies sudo apt autoremove
apt list --installed List installed packages apt list --installed | grep python
apt search [term] Search packages apt search "web server"
apt show [pkg] Show package details apt show curl
apt edit-sources Edit sources.list sudo apt edit-sources
dpkg -i [.deb] Install local .deb file sudo dpkg -i package.deb
dpkg -l List installed .deb packages dpkg -l | grep mysql

System Information

Command Description Example
uname -a All system info (kernel, arch, hostname) uname -a
uname -r Kernel release uname -r
lscpu CPU architecture details lscpu
lspci List PCI devices lspci -v
lsusb List USB devices lsusb -t
lsblk List block devices lsblk -o NAME,SIZE,TYPE
lshw Full hardware inventory sudo lshw -short
dmidecode DMI/BIOS/System info sudo dmidecode -t memory
free -h Memory usage free -h
uptime System uptime and load uptime
dmesg Kernel ring buffer messages dmesg | tail -20
hostnamectl Hostname and OS info hostnamectl
timedatectl System time/date/zone timedatectl list-timezones
who / w Who is logged in who -a
last Last logged-in users last -10

Quick Reference โ€” Combined Shortcuts

Shortcut Effect
Ctrl+C Kill foreground process (SIGINT)
Ctrl+D EOF / exit shell
Ctrl+Z Suspend foreground process (SIGTSTP)
Ctrl+L Clear terminal
Ctrl+R Reverse search command history
Ctrl+W Delete word before cursor
Ctrl+U Delete from cursor to start of line
!! Repeat last command
!$ Last argument of previous command
!n Repeat nth command from history
~/.bashrc Bash init script (user)
~/.bash_aliases Common alias storage
~/.profile Login shell init
/etc/environment System-wide env vars

This is a living reference. Add sections or commands as needed. Always verify with man [command] or [command] --help for the latest options on your system.