Linux Cheatsheet

This cheatsheet provides a comprehensive and practical reference for common Linux commands. It covers file operations, process management, networking, system info, permissions, advanced command combos, and more. Use it to boost your productivity and master Linux workflows.

File Operations

ls
List directory contents
ls -lh
List with human-readable file sizes
ls -la
List all files including hidden, with details
tree
Display directory tree structure
cd ~
Go to home directory
cd -
Go to previous directory
pwd
Print working directory
cp -r [src] [dest]
Copy directories recursively
mv [src] [dest]
Move or rename files/directories
rm -rf [dir]
Force remove directory and contents
find [dir] -type f -mtime -1
Find files modified in the last day
du -sh [dir]
Show total size of a directory
ln -s [target] [link]
Create a symbolic link
chmod +x [file]
Make a file executable
chown user:group [file]
Change file owner and group
tar -czf archive.tar.gz [dir]
Create a gzipped tar archive
tar -xzf archive.tar.gz
Extract a gzipped tar archive
zip -r archive.zip [dir]
Create a zip archive
unzip archive.zip
Extract a zip archive

Process Management

ps aux
Show running processes
top
Display real-time process info
htop
Interactive process viewer (if installed)
kill [pid]
Kill a process by PID
killall [name]
Kill processes by name
bg
Resume a job in the background
fg
Bring a job to the foreground
jobs
List active jobs
nice [command]
Run a command with modified scheduling priority
renice [pid] [value]
Change priority of a running process
pkill [pattern]
Kill processes by pattern
xkill
Kill a window by clicking on it

Networking

ifconfig
Show network interfaces (older systems)
ip a
Show network interfaces (modern systems)
ping [host]
Ping a host
curl [url]
Transfer data from/to a server
wget [url]
Download files from the web
netstat -tuln
Show listening ports
ss -tuln
Show listening ports (modern)
ssh [user]@[host]
Connect to a remote host via SSH
scp [src] [user]@[host]:[dest]
Copy files over SSH
traceroute [host]
Show route to host
nslookup [domain]
Query DNS information
dig [domain]
Query DNS information (detailed)
hostname -I
Show local IP addresses

System Info

uname -a
Show system information
df -h
Show disk usage
du -sh [dir]
Show directory size
free -h
Show memory usage
uptime
Show system uptime
whoami
Show current user
date
Show current date and time
last
Show last logged in users
dmesg | less
View kernel ring buffer
lscpu
Show CPU architecture info
lsblk
List block devices
lsusb
List USB devices
lspci
List PCI devices
env
Show environment variables

Permissions

chmod [options] [file]
Change file permissions
chown [user]:[group] [file]
Change file owner and group
sudo [command]
Run command as superuser
umask [value]
Set default permissions for new files
passwd
Change user password
groups
Show group memberships for current user

Package Management

apt update
Update package lists (Debian/Ubuntu)
apt upgrade
Upgrade packages (Debian/Ubuntu)
apt install [pkg]
Install a package (Debian/Ubuntu)
apt remove [pkg]
Remove a package (Debian/Ubuntu)
apt search [pkg]
Search for a package (Debian/Ubuntu)
yum install [pkg]
Install a package (RHEL/CentOS)
yum update
Update packages (RHEL/CentOS)
dnf install [pkg]
Install a package (Fedora)
pacman -S [pkg]
Install a package (Arch)
zypper install [pkg]
Install a package (openSUSE)
snap install [pkg]
Install a snap package
flatpak install [pkg]
Install a flatpak package

Text Processing

cat [file]
Display file contents
less [file]
View file with paging
more [file]
View file with paging (alternative)
head [file]
Show first lines of a file
tail [file]
Show last lines of a file
tail -f [file]
Follow appended output in real time
grep [pattern] [file]
Search for pattern in file
egrep [pattern] [file]
Extended grep (supports regex)
sort [file]
Sort lines in a file
uniq [file]
Report or filter repeated lines
wc -l [file]
Count lines in a file
awk '{print $1}' [file]
Pattern scanning and processing
sed 's/a/b/g' [file]
Stream editor for filtering and transforming text
cut -d: -f1 [file]
Remove sections from each line of files
paste [file1] [file2]
Merge lines of files
diff [file1] [file2]
Compare files line by line
comm [file1] [file2]
Compare two sorted files line by line

Others

man [command]
Show manual for a command
history
Show command history
echo [text]
Display a line of text
clear
Clear the terminal screen
exit
Exit the shell
alias ll='ls -l'
Create a shortcut for a command
crontab -e
Edit user cron jobs
at [time] [command]
Schedule a command to run once at a certain time
shutdown -h now
Shutdown the system immediately
reboot
Reboot the system

Command Combos

find . -type f -name '*.log' | xargs rm -f
Find and delete all .log files recursively
cat *.log | grep 'ERROR' | less
View all ERROR lines in log files with paging
ps aux | grep python | grep -v grep
Find all running python processes
du -sh * | sort -hr | head -10
Show top 10 largest items in current directory
grep -r 'TODO' . | less
Recursively search for TODO in all files and page output
awk -F: '{print $1}' /etc/passwd | sort | uniq
List all unique users
for f in *.txt; do grep 'pattern' "$f"; done
Search for a pattern in all .txt files
cat file.txt | tr 'a-z' 'A-Z'
Convert file content to uppercase
df -h | grep '/dev/sd'
Show disk usage for physical disks only
history | tail -20
Show last 20 commands from history

Categories

  • File Operations

    Commands for managing files and directories, such as listing, copying, moving, deleting, and compressing.

  • Process Management

    Commands for viewing, controlling, and prioritizing running processes and jobs.

  • Networking

    Commands for network configuration, diagnostics, and remote access.

  • System Info

    Commands for viewing system, disk, memory, and hardware information.

  • Permissions

    Commands for managing file permissions, ownership, and user groups.

  • Package Management

    Commands for installing, updating, searching, and managing software packages.

  • Text Processing

    Commands for viewing, searching, transforming, and comparing text files.

  • Others

    Other useful commands for daily Linux usage and automation.

  • Command Combos

    Powerful multi-step workflows and advanced usage patterns for real-world scenarios.

Features

  • Quick search functionality
  • Organized by categories
  • Clear command descriptions
  • Common and advanced use cases covered
  • Easy to copy commands
  • Responsive design
  • Perfect for quick reference