cat <file> | Display file content |
cat -n <file> | Display with line numbers |
less <file> | View file with pagination |
more <file> | View file (forward only) |
head <file> | Show first 10 lines |
head -n 20 <file> | Show first 20 lines |
tail <file> | Show last 10 lines |
tail -f <file> | Follow file updates |
tail -n 50 <file> | Show last 50 lines |
wc <file> | Count lines, words, chars |
wc -l <file> | Count lines only |
diff <file1> <file2> | Compare files |
diff -u <f1> <f2> | Unified diff format |
sort <file> | Sort lines |
sort -r <file> | Sort reverse |
sort -n <file> | Sort numerically |
uniq <file> | Remove duplicate lines |
uniq -c <file> | Count occurrences |
cut -d: -f1 <file> | Cut by delimiter, field 1 |
cut -c1-10 <file> | Cut characters 1-10 |
awk '{print $1}' <file> | Print first column |
awk -F: '{print $1}' <file> | Print with delimiter |
sed 's/old/new/g' <file> | Replace all occurrences |
sed -i 's/old/new/g' <file> | Replace in place |
tr a-z A-Z | Translate characters |
xargs <cmd> | Build command from stdin |
find . -name "*.txt" | Find by name pattern |
find . -iname "*.txt" | Case insensitive find |
find . -type f | Find files only |
find . -type d | Find directories only |
find . -mtime -7 | Modified in last 7 days |
find . -mmin -60 | Modified in last 60 min |
find . -size +100M | Files larger than 100MB |
find . -empty | Find empty files/dirs |
find . -name "*.log" -delete | Find and delete |
find . -exec cmd {} \; | Execute command on results |
locate <name> | Find using index (fast) |
which <cmd> | Find command path |
whereis <cmd> | Find binary, source, manual |
grep "pattern" <file> | Search in file |
grep -r "pattern" <dir> | Search recursively |
grep -i "pattern" <file> | Case insensitive search |
grep -n "pattern" <file> | Show line numbers |
grep -v "pattern" <file> | Invert match (exclude) |
grep -c "pattern" <file> | Count matches |
grep -l "pattern" * | List matching files |
grep -w "word" <file> | Match whole word |
grep -E "regex" <file> | Extended regex |
grep -A 3 "pattern" <file> | Show 3 lines after match |
grep -B 3 "pattern" <file> | Show 3 lines before match |
grep -C 3 "pattern" <file> | Show context (before+after) |
chmod 755 <file> | Set permissions (rwxr-xr-x) |
chmod 644 <file> | Set permissions (rw-r--r--) |
chmod +x <file> | Add execute permission |
chmod -w <file> | Remove write permission |
chmod u+x <file> | Add execute for owner |
chmod g+w <file> | Add write for group |
chmod o-r <file> | Remove read for others |
chmod -R 755 <dir> | Recursive permission change |
chown <user> <file> | Change owner |
chown <user>:<group> <file> | Change owner and group |
chown -R <user> <dir> | Recursive owner change |
chgrp <group> <file> | Change group |
umask 022 | Set default permissions |
whoami | Current username |
id | User and group IDs |
id <user> | Show user info |
users | Logged in users |
who | Who is logged in |
w | Who + what they are doing |
last | Login history |
sudo <cmd> | Run as superuser |
sudo -u <user> <cmd> | Run as another user |
su - <user> | Switch user |
passwd | Change password |
useradd <user> | Add user |
useradd -m -s /bin/bash <user> | Add user with home & shell |
userdel -r <user> | Delete user with home |
usermod -aG <group> <user> | Add user to group |
groups <user> | Show user groups |
ps | List processes |
ps aux | All processes detailed |
ps aux | grep <name> | Find process by name |
pgrep <name> | Get PID by name |
top | Interactive process viewer |
htop | Better process viewer |
kill <pid> | Kill process by ID |
kill -9 <pid> | Force kill process |
killall <name> | Kill by name |
pkill <pattern> | Kill by pattern |
bg | Send to background |
fg | Bring to foreground |
jobs | List background jobs |
<cmd> & | Run in background |
nohup <cmd> & | Run immune to hangups |
nice -n 10 <cmd> | Run with priority |
renice -n 10 -p <pid> | Change process priority |
systemctl start <service> | Start service |
systemctl stop <service> | Stop service |
systemctl restart <service> | Restart service |
systemctl reload <service> | Reload configuration |
systemctl status <service> | Check service status |
systemctl enable <service> | Enable at boot |
systemctl disable <service> | Disable at boot |
systemctl is-active <service> | Check if running |
systemctl is-enabled <service> | Check if enabled |
systemctl list-units --type=service | List all services |
systemctl list-unit-files | List unit files |
systemctl daemon-reload | Reload systemd |
systemctl mask <service> | Completely disable |
journalctl | View all logs |
journalctl -u <service> | Logs for service |
journalctl -f | Follow logs |
journalctl -f -u <service> | Follow service logs |
journalctl --since today | Logs since today |
journalctl --since "1 hour ago" | Logs from last hour |
journalctl -p err | Error logs only |
journalctl -b | Logs since boot |
journalctl -b -1 | Previous boot logs |
journalctl --disk-usage | Show log disk usage |
journalctl --vacuum-size=100M | Reduce logs to 100MB |
apt update | Update package list |
apt upgrade | Upgrade all packages |
apt install <pkg> | Install package |
apt remove <pkg> | Remove package |
apt purge <pkg> | Remove with config |
apt autoremove | Remove unused packages |
apt search <name> | Search packages |
apt show <pkg> | Show package info |
apt list --installed | List installed packages |
dpkg -i <file>.deb | Install .deb file |
dpkg -l | List installed (dpkg) |
dnf check-update | Check for updates |
dnf upgrade | Upgrade all packages |
dnf install <pkg> | Install package |
dnf remove <pkg> | Remove package |
dnf autoremove | Remove unused |
dnf search <name> | Search packages |
dnf info <pkg> | Show package info |
dnf list installed | List installed |
rpm -ivh <file>.rpm | Install .rpm file |
rpm -qa | List all packages |
df -h | Disk space usage |
df -i | Inode usage |
du -sh <dir> | Directory size |
du -sh * | Size of each item |
du -sh * | sort -h | Size sorted |
lsblk | List block devices |
lsblk -f | List with filesystem |
blkid | Show block device UUIDs |
fdisk -l | List partitions |
mount | Show mounted filesystems |
mount /dev/sdb1 /mnt | Mount device |
mount -o loop file.iso /mnt | Mount ISO file |
umount /mnt | Unmount |
umount -l /mnt | Lazy unmount |
mkfs.ext4 /dev/sdb1 | Create ext4 filesystem |
mkfs.xfs /dev/sdb1 | Create XFS filesystem |
fsck /dev/sdb1 | Check filesystem |
/etc/fstab | Permanent mount config |
tar -cvf archive.tar <dir> | Create tar archive |
tar -xvf archive.tar | Extract tar archive |
tar -czvf archive.tar.gz <dir> | Create gzipped tar |
tar -xzvf archive.tar.gz | Extract gzipped tar |
tar -cjvf archive.tar.bz2 <dir> | Create bzip2 tar |
tar -xjvf archive.tar.bz2 | Extract bzip2 tar |
tar -tvf archive.tar | List tar contents |
gzip <file> | Compress with gzip |
gunzip <file>.gz | Decompress gzip |
zip -r archive.zip <dir> | Create zip archive |
unzip archive.zip | Extract zip archive |
unzip -l archive.zip | List zip contents |
ip addr | Show IP addresses |
ip link | Show network interfaces |
ip route | Show routing table |
ifconfig | Network interfaces (legacy) |
ping <host> | Check connectivity |
ping -c 4 <host> | Ping 4 times |
traceroute <host> | Trace packet route |
netstat -tuln | Show listening ports |
ss -tuln | Show listening ports (modern) |
ss -p | Show process using ports |
host <domain> | DNS lookup |
nslookup <domain> | DNS lookup |
dig <domain> | Detailed DNS lookup |
curl <url> | Fetch URL content |
curl -O <url> | Download file |
curl -o <name> <url> | Download with name |
curl -I <url> | Get headers only |
wget <url> | Download file |
wget -c <url> | Resume download |
wget -r <url> | Recursive download |
scp <file> <user>@<host>:<path> | Secure copy to remote |
scp <user>@<host>:<file> . | Copy from remote |
scp -r <dir> <user>@<host>: | Copy directory to remote |
rsync -avz <src> <dst> | Sync files efficiently |
ssh <user>@<host> | SSH connection |
ssh -p <port> <user>@<host> | SSH on custom port |
crontab -e | Edit crontab |
crontab -l | List cron jobs |
crontab -r | Remove all cron jobs |
* * * * * cmd | Every minute |
0 * * * * cmd | Every hour |
0 0 * * * cmd | Every day at midnight |
0 0 * * 0 cmd | Every Sunday |
0 0 1 * * cmd | First of month |
*/5 * * * * cmd | Every 5 minutes |
0 9-17 * * 1-5 cmd | 9-17 weekdays |
# Cron format:
# ┌───────────── minute (0-59)
# │ ┌───────────── hour (0-23)
# │ │ ┌───────────── day of month (1-31)
# │ │ │ ┌───────────── month (1-12)
# │ │ │ │ ┌───────────── day of week (0-6, Sunday=0)
# │ │ │ │ │
# * * * * * command
# Examples:
0 2 * * * /backup.sh # Daily at 2 AM
*/10 * * * * /check.sh # Every 10 minutes
0 0 * * 0 /weekly.sh # Weekly on Sunday uname -a | System information |
uname -r | Kernel version |
hostname | Show hostname |
hostnamectl | Detailed host info |
uptime | System uptime |
date | Current date/time |
timedatectl | Time and timezone |
cal | Show calendar |
free -h | Memory usage |
lscpu | CPU information |
lsmem | Memory information |
lspci | List PCI devices |
lsusb | List USB devices |
dmesg | Kernel messages |
dmesg | tail | Recent kernel messages |
env | Show environment variables |
printenv | Print environment |
echo $PATH | Show PATH variable |
export VAR=value | Set environment variable |
unset VAR | Remove variable |
source ~/.bashrc | Reload bash config |
alias ll="ls -la" | Create alias |
alias | List all aliases |
Ctrl + C | Cancel current command |
Ctrl + Z | Suspend current process |
Ctrl + D | Exit shell / EOF |
Ctrl + L | Clear screen |
Ctrl + R | Search command history |
Ctrl + A | Go to line start |
Ctrl + E | Go to line end |
Tab | Auto-complete |
cmd1 | cmd2 | Pipe output to next |
cmd > file | Redirect output to file |
cmd >> file | Append output to file |
cmd 2>&1 | Redirect stderr to stdout |
cmd &> file | Redirect all output |
!! | Repeat last command |
!$ | Last argument of prev cmd |
history | Show command history |
man to read the manual--help flag for quick helprm -rfecho before runningalias for frequently used commands