Linux Command Reference
~80 essential Linux commands organized by category. Search by command name, description, or example.
File System
ls
List directory contents
ls [options] [path]- $ ls -la
- $ ls -lh /var
- $ ls -t
cd
Change directory
cd [directory]- $ cd /home
- $ cd ..
- $ cd ~
pwd
Print working directory
pwd- $ pwd
mkdir
Create directory
mkdir [options] directory- $ mkdir project
- $ mkdir -p a/b/c
- $ mkdir -m 755 dir
rm
Remove files/directories
rm [options] file- $ rm file.txt
- $ rm -rf directory
- $ rm -i *.log
cp
Copy files/directories
cp [options] source dest- $ cp file.txt backup/
- $ cp -r dir1 dir2
- $ cp -p file backup
mv
Move/rename files
mv [options] source dest- $ mv file.txt newname.txt
- $ mv *.txt folder/
find
Search for files
find path [expression]- $ find . -name '*.txt'
- $ find /var -mtime -7
- $ find . -type f -size +1M
locate
Find files by name (indexed)
locate pattern- $ locate config
- $ locate -i '*.pdf'
du
Disk usage
du [options] [path]- $ du -sh .
- $ du -h --max-depth=1
- $ du -ah
df
Disk free space
df [options] [path]- $ df -h
- $ df -i
- $ df -T
File Content
cat
Concatenate and display files
cat [options] file- $ cat file.txt
- $ cat file1 file2 > combined
- $ cat -n file.txt
head
Output first lines
head [options] file- $ head file.txt
- $ head -n 20 file.txt
- $ head -c 100 file
tail
Output last lines
tail [options] file- $ tail file.txt
- $ tail -f log.txt
- $ tail -n 50 file
less
Page through file
less [options] file- $ less file.txt
- $ less +F log.txt
more
Page through file (simpler)
more file- $ more file.txt
grep
Search text with regex
grep [options] pattern file- $ grep 'error' log.txt
- $ grep -r 'TODO' .
- $ grep -i 'warning' file
sed
Stream editor
sed [options] 'script' file- $ sed 's/old/new/g' file
- $ sed -i.bak '1d' file
- $ sed -n '10,20p' file
awk
Pattern scanning and processing
awk 'pattern {action}' file- $ awk '{print $1}' file
- $ awk -F',' '{print $2}' csv
- $ awk '/error/ {count++} END {print count}'
sort
Sort lines
sort [options] file- $ sort file.txt
- $ sort -n numbers.txt
- $ sort -t',' -k2 file.csv
wc
Word/line/byte count
wc [options] file- $ wc -l file.txt
- $ wc -w file.txt
- $ wc -c file
diff
Compare files line by line
diff [options] file1 file2- $ diff file1 file2
- $ diff -u old new
- $ diff -r dir1 dir2
Permissions
chmod
Change file permissions
chmod [options] mode file- $ chmod 755 script.sh
- $ chmod +x file
- $ chmod -R 644 dir/
chown
Change file owner
chown [options] owner[:group] file- $ chown user file
- $ chown user:group file
- $ chown -R user dir/
chgrp
Change file group
chgrp [options] group file- $ chgrp www-data file
- $ chgrp -R dev dir/
umask
Set default file permissions
umask [mode]- $ umask
- $ umask 022
- $ umask 002
Process
ps
Report process status
ps [options]- $ ps aux
- $ ps -ef
- $ ps -u $USER
top
Display processes (interactive)
top [options]- $ top
- $ top -u www-data
- $ top -p 1234
kill
Terminate process
kill [options] PID- $ kill 1234
- $ kill -9 1234
- $ kill -SIGTERM 1234
bg
Resume job in background
bg [job]- $ bg
- $ bg %1
fg
Bring job to foreground
fg [job]- $ fg
- $ fg %1
jobs
List active jobs
jobs [options]- $ jobs
- $ jobs -l
nohup
Run immune to hangups
nohup command [args]- $ nohup ./script.sh &
- $ nohup python app.py > out.log 2>&1
nice
Run with adjusted priority
nice [options] command- $ nice -n 19 ./heavy.sh
- $ nice -n -10 ./critical
Network
ping
Test network connectivity
ping [options] host- $ ping google.com
- $ ping -c 4 8.8.8.8
- $ ping -i 2 host
curl
Transfer data from URL
curl [options] URL- $ curl https://example.com
- $ curl -o file.zip URL
- $ curl -X POST -d 'data' URL
wget
Download files from web
wget [options] URL- $ wget https://example.com/file.zip
- $ wget -O out.zip URL
- $ wget -r -np URL
ssh
Secure shell remote login
ssh [options] user@host- $ ssh user@server.com
- $ ssh -i key.pem user@host
- $ ssh -p 2222 user@host
scp
Secure copy
scp [options] source dest- $ scp file user@host:/path
- $ scp -r dir user@host:/path
- $ scp user@host:file .
netstat
Network statistics
netstat [options]- $ netstat -tuln
- $ netstat -an
- $ netstat -r
ifconfig
Configure network interfaces
ifconfig [interface] [options]- $ ifconfig
- $ ifconfig eth0 up
- $ ifconfig eth0 192.168.1.10
ip
Show/manipulate routing, devices
ip [options] object command- $ ip addr
- $ ip route
- $ ip link show
dig
DNS lookup utility
dig [options] name [type]- $ dig example.com
- $ dig example.com MX
- $ dig @8.8.8.8 example.com
nslookup
Query DNS
nslookup [options] name- $ nslookup example.com
- $ nslookup -type=MX example.com
System
uname
Print system information
uname [options]- $ uname -a
- $ uname -r
- $ uname -m
hostname
Show/set system hostname
hostname [options] [name]- $ hostname
- $ hostname -I
uptime
System uptime and load
uptime- $ uptime
free
Memory usage
free [options]- $ free -h
- $ free -m
lsblk
List block devices
lsblk [options]- $ lsblk
- $ lsblk -f
mount
Mount filesystems
mount [options] device dir- $ mount
- $ mount /dev/sdb1 /mnt
- $ mount -t nfs server:/path /mnt
systemctl
Control systemd
systemctl [command] [unit]- $ systemctl status nginx
- $ systemctl start nginx
- $ systemctl enable nginx
Package Management
apt
Debian/Ubuntu package manager
apt [command] [options]- $ apt update
- $ apt install nginx
- $ apt remove package
yum
RHEL/CentOS package manager
yum [command] [options]- $ yum install nginx
- $ yum update
- $ yum remove package
dnf
Fedora package manager
dnf [command] [options]- $ dnf install nginx
- $ dnf search package
pacman
Arch package manager
pacman [options] [package]- $ pacman -S nginx
- $ pacman -Syu
- $ pacman -Qs search
brew
macOS/Linux package manager
brew [command] [formula]- $ brew install nginx
- $ brew update
- $ brew list
Compression
tar
Archive files
tar [options] archive [files]- $ tar -cvf archive.tar dir/
- $ tar -xvf archive.tar
- $ tar -czvf archive.tar.gz dir/
gzip
Compress files
gzip [options] file- $ gzip file
- $ gzip -d file.gz
- $ gzip -9 file
zip
Create ZIP archive
zip [options] archive files- $ zip archive.zip file1 file2
- $ zip -r archive.zip dir/
unzip
Extract ZIP archive
unzip [options] archive- $ unzip archive.zip
- $ unzip -l archive.zip
- $ unzip -d /path archive.zip
Users
useradd
Add user account
useradd [options] username- $ useradd john
- $ useradd -m -s /bin/bash john
passwd
Change user password
passwd [username]- $ passwd
- $ passwd john
su
Switch user
su [options] [username]- $ su root
- $ su - john
- $ su -c 'command' root
sudo
Execute as superuser
sudo [options] command- $ sudo apt update
- $ sudo -u www-data command
- $ sudo -i
whoami
Print current user
whoami- $ whoami
id
Print user/group IDs
id [options] [user]- $ id
- $ id root
- $ id -Gn
groups
Print group memberships
groups [user]- $ groups
- $ groups john