Linux Cheatsheet

Comprehensive Linux command reference with 200+ commands. Search, filter by category, and click to copy.

212 commands
Files

Navigation

pwd
cd [dir]
cd ~
cd -
cd ..

pwd - Print working directory

cd - Change directory

cd - Go to home directory

cd - Go to previous directory

cd - Go up one level

Files

Listing

ls
ls -l
ls -la
ls -lh
ls -lS
ls -lt
ls -R
tree
tree -L 2

ls - List directory contents

ls - Long format listing

ls - Include hidden files

ls - Human-readable sizes

ls - Sort by size

ls - Sort by time

ls - Recursive listing

tree - Directory tree structure

tree - Tree with depth limit

Files

File Operations

cp [src] [dest]
cp -r [src] [dest]
cp -i [src] [dest]
mv [src] [dest]
rm [file]
rm -r [dir]
rm -rf [dir]
mkdir [dir]
mkdir -p [path]
touch [file]
ln -s [target] [link]
ln [target] [link]

cp - Copy file

cp - Copy directory recursively

cp - Copy with confirmation

mv - Move or rename

rm - Remove file

rm - Remove directory

rm - Force remove (dangerous)

mkdir - Create directory

mkdir - Create nested directories

touch - Create empty file

ln - Create symbolic link

ln - Create hard link

Files

Archives

tar -cvf archive.tar [files]
tar -xvf archive.tar
tar -czvf archive.tar.gz [files]
tar -xzvf archive.tar.gz
tar -cjvf archive.tar.bz2 [files]
zip -r archive.zip [dir]
unzip archive.zip
gzip [file]
gunzip [file.gz]

tar - Create tar archive

tar - Extract tar archive

tar - Create gzipped tar

tar - Extract gzipped tar

tar - Create bz2 tar

zip - Create zip archive

unzip - Extract zip archive

gzip - Compress file

gunzip - Decompress file

Text

Viewing

cat [file]
cat -n [file]
less [file]
more [file]
head [file]
head -n 20 [file]
tail [file]
tail -n 20 [file]
tail -f [file]

cat - Display file contents

cat - Display with line numbers

less - View with paging

more - View with paging (basic)

head - Show first 10 lines

head - Show first 20 lines

tail - Show last 10 lines

tail - Show last 20 lines

tail - Follow file in real-time

Text

Searching

grep [pattern] [file]
grep -i [pattern] [file]
grep -r [pattern] [dir]
grep -n [pattern] [file]
grep -v [pattern] [file]
grep -c [pattern] [file]
grep -l [pattern] [files]
grep -E [regex] [file]

grep - Search for pattern

grep - Case-insensitive search

grep - Recursive search

grep - Show line numbers

grep - Invert match

grep - Count matches

grep - List matching files

grep - Extended regex

Text

Processing

sort [file]
sort -r [file]
sort -n [file]
sort -u [file]
uniq [file]
uniq -c [file]
wc [file]
wc -l [file]
cut -d',' -f1 [file]
tr 'a-z' 'A-Z'
sed 's/old/new/g' [file]
awk '{print $1}' [file]
diff [file1] [file2]

sort - Sort lines

sort - Reverse sort

sort - Numeric sort

sort - Sort and unique

uniq - Remove duplicates

uniq - Count occurrences

wc - Count lines, words, chars

wc - Count lines only

cut - Extract field

tr - Translate characters

sed - Replace text

awk - Print first column

diff - Compare files

Process

Viewing Processes

ps
ps aux
ps -ef
ps aux | grep [name]
top
htop
pgrep [name]
pidof [name]

ps - Show current processes

ps - Show all processes

ps - Full format listing

ps - Find process by name

top - Real-time process viewer

htop - Interactive process viewer

pgrep - Get PID by name

pidof - Get PID of program

Process

Managing Processes

kill [pid]
kill -9 [pid]
killall [name]
pkill [pattern]
bg
fg
jobs
[command] &
nohup [command] &
nice -n 10 [command]
renice -n 10 [pid]

kill - Terminate process

kill - Force kill process

killall - Kill by name

pkill - Kill by pattern

bg - Resume in background

fg - Bring to foreground

jobs - List background jobs

[command] - Run in background

nohup - Run immune to hangups

nice - Run with priority

renice - Change priority

System

System Info

uname -a
uname -r
hostname
uptime
date
cal
whoami
id
last
w
lscpu
lsblk
lsusb
lspci
dmesg | tail

uname - System information

uname - Kernel version

hostname - Show hostname

uptime - System uptime

date - Current date/time

cal - Show calendar

whoami - Current username

id - User and group IDs

last - Last logged in users

w - Who is logged in

lscpu - CPU information

lsblk - Block devices

lsusb - USB devices

lspci - PCI devices

dmesg - Kernel messages

System

Disk Usage

df -h
df -i
du -sh [dir]
du -sh *
du -sh * | sort -hr
ncdu
fdisk -l
mount
mount [device] [dir]
umount [dir]

df - Disk space usage

df - Inode usage

du - Directory size

du - Size of each item

du - Sorted by size

ncdu - Interactive disk usage

fdisk - List partitions

mount - Show mounted filesystems

mount - Mount filesystem

umount - Unmount filesystem

System

Memory

free -h
free -m
vmstat
cat /proc/meminfo

free - Memory usage

free - Memory in MB

vmstat - Virtual memory stats

cat - Detailed memory info

Network

Network Info

ip a
ip link
ifconfig
hostname -I
cat /etc/resolv.conf
cat /etc/hosts

ip - Show IP addresses

ip - Show interfaces

ifconfig - Network config (legacy)

hostname - Show local IPs

cat - DNS servers

cat - Hosts file

Network

Connectivity

ping [host]
ping -c 4 [host]
traceroute [host]
mtr [host]
nslookup [domain]
dig [domain]
host [domain]
whois [domain]

ping - Test connectivity

ping - Ping 4 times

traceroute - Trace route to host

mtr - Network diagnostic

nslookup - DNS lookup

dig - DNS lookup (detailed)

host - DNS lookup (simple)

whois - Domain info

Network

Ports & Connections

netstat -tuln
ss -tuln
ss -tp
lsof -i :[port]
nmap [host]

netstat - Listening ports

ss - Listening ports (modern)

ss - TCP connections

lsof - Process using port

nmap - Port scan

Network

Transfer

curl [url]
curl -O [url]
curl -I [url]
wget [url]
wget -c [url]
scp [file] [user]@[host]:[path]
rsync -avz [src] [dest]

curl - Fetch URL content

curl - Download file

curl - Get headers only

wget - Download file

wget - Resume download

scp - Copy via SSH

rsync - Sync files

Permissions

File Permissions

chmod 755 [file]
chmod 644 [file]
chmod +x [file]
chmod -x [file]
chmod u+w [file]
chmod -R 755 [dir]
chown [user] [file]
chown [user]:[group] [file]
chown -R [user] [dir]
chgrp [group] [file]

chmod - Set rwxr-xr-x

chmod - Set rw-r--r--

chmod - Add execute permission

chmod - Remove execute

chmod - Add write for owner

chmod - Recursive chmod

chown - Change owner

chown - Change owner and group

chown - Recursive chown

chgrp - Change group

💡 r=4, w=2, x=1. Example: 755 = rwxr-xr-x

Permissions

Sudo & Users

sudo [command]
sudo -i
sudo -u [user] [command]
su - [user]
visudo

sudo - Run as superuser

sudo - Root shell

sudo - Run as user

su - Switch user

visudo - Edit sudoers file

Users

User Management

useradd [user]
useradd -m [user]
userdel [user]
userdel -r [user]
usermod -aG [group] [user]
passwd [user]
chage -l [user]

useradd - Create user

useradd - Create with home dir

userdel - Delete user

userdel - Delete with home dir

usermod - Add user to group

passwd - Set password

chage - Password expiry info

Users

Group Management

groupadd [group]
groupdel [group]
groups [user]
cat /etc/passwd
cat /etc/group

groupadd - Create group

groupdel - Delete group

groups - Show user groups

cat - List all users

cat - List all groups

Packages

APT (Debian/Ubuntu)

apt update
apt upgrade
apt install [pkg]
apt remove [pkg]
apt purge [pkg]
apt autoremove
apt search [pkg]
apt show [pkg]
apt list --installed
dpkg -i [file.deb]

apt - Update package list

apt - Upgrade packages

apt - Install package

apt - Remove package

apt - Remove with config

apt - Remove unused

apt - Search packages

apt - Package info

apt - List installed

dpkg - Install .deb file

Packages

YUM/DNF (RHEL/Fedora)

yum update
yum install [pkg]
yum remove [pkg]
yum search [pkg]
dnf install [pkg]
rpm -ivh [file.rpm]

yum - Update packages

yum - Install package

yum - Remove package

yum - Search packages

dnf - Install (Fedora)

rpm - Install .rpm file

Packages

Other Package Managers

pacman -S [pkg]
pacman -Syu
snap install [pkg]
flatpak install [pkg]

pacman - Install (Arch)

pacman - Update all (Arch)

snap - Install snap

flatpak - Install flatpak

Advanced

Find Command

find [dir] -name [pattern]
find [dir] -type f
find [dir] -type d
find [dir] -mtime -7
find [dir] -size +100M
find [dir] -exec [cmd] {} \;
find [dir] -name '*.log' -delete

find - Find by name

find - Find files only

find - Find directories

find - Modified in 7 days

find - Larger than 100MB

find - Execute command

find - Find and delete

Advanced

Services (systemd)

systemctl start [service]
systemctl stop [service]
systemctl restart [service]
systemctl status [service]
systemctl enable [service]
systemctl disable [service]
systemctl list-units
journalctl -u [service]
journalctl -f

systemctl - Start service

systemctl - Stop service

systemctl - Restart service

systemctl - Service status

systemctl - Enable at boot

systemctl - Disable at boot

systemctl - List all units

journalctl - Service logs

journalctl - Follow system logs

Advanced

Cron Jobs

crontab -e
crontab -l
crontab -r

crontab - Edit cron jobs

crontab - List cron jobs

crontab - Remove all cron jobs

💡 Format: minute hour day month weekday command

Advanced

Useful Combos

find . -name '*.log' | xargs rm
ps aux | grep [name] | awk '{print $2}'
du -sh * | sort -hr | head -10
history | grep [cmd]
watch -n 1 [command]
time [command]
xargs -I {} [cmd] {}

find - Delete all .log files

ps - Get PIDs

du - Top 10 largest

history - Search history

watch - Run every second

time - Measure execution time

xargs - Use input as argument

Quick Reference

List files:

ls -la

Find files:

find . -name "*"

Search text:

grep pattern file

Disk usage:

df -h

About Linux Commands

Linux commands are the foundation of system administration and development. This cheatsheet covers essential commands for file management, text processing, process control, networking, and more.