ls Files & Directories
Copy ls [options] [path]
List directory contents
ls -la /home cd Files & Directories
Copy cd [directory]
Change directory
cd /var/log pwd Files & Directories
Copy pwd
Print working directory
pwd mkdir Files & Directories
Copy mkdir [-p] <dir>
Create directory (-p creates parents)
mkdir -p /tmp/a/b/c rm Files & Directories
Copy rm [-rf] <file>
Remove files or directories
rm -rf /tmp/old cp Files & Directories
Copy cp [-r] <src> <dst>
Copy files or directories
cp -r /src /dst mv Files & Directories
Copy mv <src> <dst>
Move or rename files
mv old.txt new.txt find Files & Directories
Copy find <path> [options]
Search for files in directory tree
find / -name '*.log' -mtime +7 touch Files & Directories
Copy touch <file>
Create empty file or update timestamp
touch newfile.txt ln Files & Directories
Copy ln [-s] <target> <link>
Create hard or symbolic links
ln -s /etc/nginx nginx stat Files & Directories
Copy stat <file>
Display file or filesystem status
stat /etc/passwd file Files & Directories
Copy file <file>
Determine file type
file image.png tree Files & Directories
Copy tree [-L n] [path]
Display directory tree (-L depth)
tree -L 2 /var du Files & Directories
Copy du [-sh] [path]
Estimate file/directory space usage
du -sh /var/log df Files & Directories
Copy df [-h]
Report disk space usage
df -h cat [file...]
Concatenate and print files
cat /etc/hostname less <file>
View file contents page by page
less /var/log/syslog head [-n N] <file>
Output first N lines of file
head -n 20 file.log tail [-n N] [-f] <file>
Output last N lines; -f follows
tail -f /var/log/syslog grep [options] <pattern> <file>
Search text using patterns
grep -rn 'error' /var/log sed 's/old/new/g' <file>
Stream editor for filtering/transforming text
sed -i 's/foo/bar/g' file.txt awk '{print $1}' <file>
Pattern scanning and text processing
awk -F: '{print $1}' /etc/passwd sort [options] <file>
Sort lines of text
sort -k2 -n file.txt uniq [-c] <file>
Filter duplicate lines
sort file.txt | uniq -c wc [-lwc] <file>
Count lines, words, characters
wc -l /etc/passwd cut -d',' -f1 <file>
Remove sections from lines
cut -d':' -f1 /etc/passwd tr <set1> <set2>
Translate or delete characters
echo 'hello' | tr 'a-z' 'A-Z' diff <file1> <file2>
Compare files line by line
diff old.conf new.conf patch <file> <patchfile>
Apply a patch to files
patch file.c fix.patch cmd | xargs <command>
Build and execute command lines from stdin
find . -name '*.tmp' | xargs rm cmd | tee <file>
Read stdin and write to stdout and file
ls | tee output.txt echo [options] <text>
Print text to stdout
echo -e 'line1\nline2' ping [-c N] <host>
Send ICMP echo requests to network host
ping -c 4 google.com curl [options] <url>
Transfer data to/from server
curl -X POST -d '{"key":"val"}' https://api.example.com wget [options] <url>
Non-interactive network downloader
wget -O file.zip https://example.com/file.zip scp <src> [user@]host:<dst>
Secure copy over SSH
scp file.txt user@host:/tmp rsync [options] <src> <dst>
Fast, versatile remote file copy
rsync -avz ./src user@host:/var/www netstat [-tulnp]
Network statistics and connections
netstat -tulnp ss [-tulnp]
Socket statistics (modern netstat)
ss -tulnp ifconfig [interface]
Configure network interfaces (legacy)
ifconfig eth0 ip [addr|route|link]
Show/manipulate routing and devices
ip addr show hostname [-I]
Show or set system hostname
hostname -I nmap [options] <host>
Network exploration and port scanning
nmap -sV 192.168.1.0/24 traceroute <host>
Trace network path to host
traceroute google.com dig <domain> [type]
DNS lookup utility
dig google.com MX nslookup <domain>
Query DNS name servers
nslookup example.com ps [aux]
Report process status
ps aux | grep nginx top Process Management
Copy top
Dynamic real-time process monitor
top -u www-data htop Process Management
Copy htop
Interactive process viewer (enhanced top)
htop kill Process Management
Copy kill [-signal] <pid>
Send signal to process by PID
kill -9 1234 killall Process Management
Copy killall <name>
Kill processes by name
killall nginx pkill Process Management
Copy pkill [options] <pattern>
Signal processes by name pattern
pkill -f 'python script.py' nohup Process Management
Copy nohup <command> &
Run command immune to hangups
nohup ./server.sh & bg [%jobid]
Resume suspended job in background
bg %1 fg [%jobid]
Bring job to foreground
fg %1 jobs Process Management
Copy jobs [-l]
List active jobs in current shell
jobs -l lsof Process Management
Copy lsof [-i :port]
List open files and sockets
lsof -i :80 nice Process Management
Copy nice -n <val> <cmd>
Run command with modified scheduling priority
nice -n 10 ./backup.sh renice Process Management
Copy renice <val> -p <pid>
Alter priority of running process
renice -5 -p 1234 screen Process Management
Copy screen [-S name]
Terminal multiplexer (detachable sessions)
screen -S mysession tmux Process Management
Copy tmux [new|attach]
Terminal multiplexer with panes/windows
tmux new -s work uname [-a]
Print system information
uname -a whoami
Print current user name
whoami id [user]
Print user identity and groups
id ubuntu date [format]
Print or set system date/time
date '+%Y-%m-%d %H:%M:%S' uptime
Show how long the system has been running
uptime w [user]
Show who is logged in and what they are doing
w last [user]
Show last login history
last root free -h
Display amount of free/used memory
free -h lscpu
Display CPU architecture information
lscpu lsblk [-f]
List block devices
lsblk -f lspci [-v]
List PCI devices
lspci -v dmesg | tail
Print kernel ring buffer messages
dmesg | grep error env [var=val] [cmd]
Print environment or run command in modified env
env | grep PATH export VAR=value
Set environment variable for child processes
export PATH=$PATH:/usr/local/bin history [n]
Show command history
history | grep ssh alias name='cmd'
Create command alias
alias ll='ls -la' which <command>
Locate a command in PATH
which python3 whereis <command>
Locate binary, source and manual for command
whereis nginx man <command>
Display manual page for command
man grep chmod <mode> <file>
Change file permissions
chmod 755 script.sh chown user:group <file>
Change file owner and group
chown www-data:www-data /var/www chgrp <group> <file>
Change group ownership
chgrp developers project/ sudo [command]
Execute command as superuser
sudo systemctl restart nginx su [-] [user]
Switch user identity
su - postgres useradd [-m] <user>
Create a new user account
useradd -m -s /bin/bash deploy passwd [user]
Change user password
passwd deploy groupadd <group>
Create a new group
groupadd developers usermod -aG <group> <user>
Modify user account
usermod -aG docker ubuntu visudo
Safely edit sudoers file
sudo visudo tar [czf|xzf] <archive> [files]
Archive files (c=create, x=extract, z=gzip, f=file)
tar czf backup.tar.gz /var/www gzip [-d] <file>
Compress or decompress files
gzip -9 largefile.log gunzip <file.gz>
Decompress gzip files
gunzip archive.tar.gz zip [-r] <archive> <files>
Package and compress files
zip -r site.zip /var/www unzip <archive> [-d dir]
Extract compressed ZIP files
unzip site.zip -d /tmp/site bzip2 [-d] <file>
Block-sorting file compressor
bzip2 -d file.bz2 xz [-d] <file>
Compress files with xz (better ratio than gzip)
xz -9 bigfile.tar apt Package Management
Copy apt [install|remove|update] <pkg>
Debian/Ubuntu package manager
apt install -y nginx apt-get Package Management
Copy apt-get [install|remove] <pkg>
Debian/Ubuntu package manager (legacy)
apt-get install curl dpkg Package Management
Copy dpkg [-i|-r] <package.deb>
Debian package manager
dpkg -i package.deb yum Package Management
Copy yum [install|remove|update] <pkg>
RHEL/CentOS 7 package manager
yum install -y epel-release dnf Package Management
Copy dnf [install|remove|update] <pkg>
Fedora/RHEL 8+ package manager
dnf install nginx rpm Package Management
Copy rpm [-ivh|-e] <package.rpm>
RPM package manager
rpm -ivh package.rpm snap Package Management
Copy snap [install|remove] <pkg>
Install snap packages
snap install docker systemctl Package Management
Copy systemctl [start|stop|status] <svc>
Control systemd services and units
systemctl enable --now nginx journalctl Package Management
Copy journalctl [-u svc] [-f] [-n N]
Query systemd journal logs
journalctl -u nginx -n 50 --no-pager crontab Package Management
Copy crontab [-e|-l|-r]
Schedule recurring commands
crontab -e mount Files & Directories
Copy mount <device> <mountpoint>
Mount a filesystem
mount /dev/sdb1 /mnt/data umount Files & Directories
Copy umount <mountpoint>
Unmount a filesystem
umount /mnt/data fdisk Files & Directories
Copy fdisk [-l] [device]
Manipulate disk partition table
fdisk -l /dev/sda