From first command to production administration, everything simplified
| Distro | Base | Pkg Manager | Use Case |
|---|---|---|---|
| Ubuntu | Debian | apt | General purpose, cloud VMs, most popular |
| Debian | Independent | apt | Servers, stability-focused |
| RHEL | Independent | yum / dnf | Enterprise production, paid support |
| CentOS / Rocky | RHEL | yum / dnf | Enterprise (free RHEL alternative) |
| Fedora | RHEL upstream | dnf | Cutting-edge features, developer desktop |
| Alpine | Independent | apk | Containers, minimal ~5MB base image |
| Amazon Linux | RHEL | yum | AWS-optimized instances |
| SUSE / openSUSE | Independent | zypper | Enterprise (SAP, Europe) |
| Arch | Independent | pacman | Rolling release, advanced users |
| Symbol | Type | Example |
|---|---|---|
| - | Regular file | /etc/passwd |
| d | Directory | /home/alice |
| l | Symbolic link | /usr/bin/python β python3 |
| b | Block device | /dev/sda |
| c | Character device | /dev/tty |
| p | Named pipe (FIFO) | mkfifo mypipe |
| s | Socket | /var/run/docker.sock |
Use ls -l, first character shows the type
| Command | Description | Example |
|---|---|---|
| pwd | Print working directory | pwd β /home/alice |
| ls | List directory contents | ls -la (all + details) |
| cd | Change directory | cd /var/log, cd .., cd ~ |
| mkdir | Create directory | mkdir -p dir/sub/deep |
| rmdir | Remove empty directory | rmdir olddir |
| touch | Create file / update timestamp | touch newfile.txt |
| cp | Copy files/directories | cp -r src/ dest/ |
| mv | Move or rename | mv old.txt new.txt |
| rm | Remove files/directories | rm -rf dir/ (caution!) |
| find | Search for files | find / -name "*.log" |
| locate | Fast file search (indexed) | locate nginx.conf |
| which | Show command path | which python3 |
| file | Identify file type | file image.png |
| stat | Detailed file info | stat /etc/passwd |
| tree | Directory tree view | tree -L 2 |
| ln | Create links | ln -s target link (symlink) |
| realpath | Resolve full path | realpath ./script.sh |
| Command | Description | Example |
|---|---|---|
| cat | Display entire file | cat /etc/hostname |
| less | Paginated viewer (scroll) | less /var/log/syslog |
| head | First N lines | head -20 file.txt |
| tail | Last N lines / follow | tail -f /var/log/syslog |
| wc | Count lines, words, bytes | wc -l file.txt |
| sort | Sort lines | sort -n numbers.txt |
| uniq | Remove adjacent duplicates | sort file | uniq -c |
| diff | Compare two files | diff file1 file2 |
| tee | Read stdin, write to file + stdout | echo hi | tee out.txt |
| cut | Extract columns | cut -d: -f1 /etc/passwd |
| tr | Translate / delete characters | echo HELLO | tr A-Z a-z |
| Pattern | Meaning |
|---|---|
| * | Match any characters (zero or more) |
| ? | Match exactly one character |
| [abc] | Match one of the listed characters |
| [0-9] | Match a range of characters |
| Operator | Function |
|---|---|
| > | Redirect stdout (overwrite) |
| >> | Redirect stdout (append) |
| < | Redirect stdin (input) |
| 2> | Redirect stderr |
| &> | Redirect both stdout + stderr |
| | | Pipe, send output to next command |
Aliases go in ~/.bashrc or ~/.zshrc for persistence
Every file has 3 permission groups:
| Group | Symbol | Applies to |
|---|---|---|
| Owner | u | The file's creator |
| Group | g | Users in the file's group |
| Others | o | Everyone else |
Each group has 3 permissions:
| Permission | Symbol | Numeric | File | Directory |
|---|---|---|---|---|
| Read | r | 4 | View contents | List files |
| Write | w | 2 | Modify | Create/delete files |
| Execute | x | 1 | Run as program | Enter (cd into) |
Example: rwxr-xr-- = 754
-rwxr-xr-- 1 alice devs 4096 file.txt
βββOwnerβββGroupββOthersβ
| Command | Description | Example |
|---|---|---|
| chmod | Change mode | chmod 755 script.sh |
| chmod | Symbolic mode | chmod u+x,g-w file |
| chown | Change owner | chown alice:devs file |
| chgrp | Change group | chgrp devs file |
| umask | Default permission mask | umask 022 β new files get 644 |
Symbolic: u (user), g (group), o (others), a (all). + add, - remove, = set exact
| Permission | Numeric | Symbol | Effect |
|---|---|---|---|
| SUID | 4000 | s on owner x | Run as file owner (e.g. /usr/bin/passwd) |
| SGID | 2000 | s on group x | New files inherit group / run as group |
| Sticky Bit | 1000 | t on others x | Only owner can delete files (e.g. /tmp) |
| Numeric | Symbolic | Use Case |
|---|---|---|
| 755 | rwxr-xr-x | Executables and public directories |
| 644 | rw-r--r-- | Regular files (config, text) |
| 600 | rw------- | Private files (SSH keys, secrets) |
| 700 | rwx------ | Private directories, ~/.ssh |
| 444 | r--r--r-- | Read-only for everyone |
| 777 | rwxrwxrwx | AVOID, full access to everyone |
| Command | Description | Example |
|---|---|---|
| useradd | Create user | useradd -m -s /bin/bash alice |
| usermod | Modify user | usermod -aG docker alice |
| userdel | Delete user | userdel -r alice (with home dir) |
| passwd | Set password | passwd alice |
| groupadd | Create group | groupadd devops |
| groupdel | Delete group | groupdel devops |
| id | Show user/group IDs | id alice |
| whoami | Current username | whoami β alice |
| who / w | Who is logged in | w (detailed view) |
| last | Login history | last -10 |
| su | Switch user | su - alice |
| sudo | Run as superuser | sudo apt update |
| Type | UID Range | Purpose |
|---|---|---|
| Root | 0 | Superuser, full system access |
| System | 1β999 | Services (www-data, mysql, nobody) |
| Regular | 1000+ | Human users (alice, bob) |
Check with: id username, shows UID, GID, and groups
| Mode | Key | Action |
|---|---|---|
| Normal β Insert | i | Insert before cursor |
| Normal β Insert | a | Append after cursor |
| Normal β Insert | o | Open new line below |
| Any β Normal | Esc | Return to normal mode |
| Normal | dd | Delete (cut) entire line |
| Normal | yy | Yank (copy) line |
| Normal | p | Paste after cursor |
| Normal | u | Undo |
| Normal | /pattern | Search forward |
| Normal | n / N | Next / previous match |
| Command | :w | Save file |
| Command | :q | Quit |
| Command | :wq | Save and quit |
| Command | :q! | Quit without saving |
| Command | :%s/old/new/g | Find and replace all |
Modes: Normal (navigate) β Insert (type) β Visual (select) β Command (:)
| Shortcut | Action |
|---|---|
| Ctrl+O | Save (Write Out) |
| Ctrl+X | Exit nano |
| Ctrl+K | Cut current line |
| Ctrl+U | Paste (Uncut) |
| Ctrl+W | Search text |
| Ctrl+\\ | Find and replace |
| Ctrl+G | Help |
| Ctrl+_ | Go to line number |
| Alt+U | Undo |
Nano shows shortcuts at the bottom, ^ means Ctrl
| Task | APT (Debian/Ubuntu) | YUM/DNF (RHEL/CentOS) |
|---|---|---|
| Install package | apt install nginx | dnf install nginx |
| Remove package | apt remove nginx | dnf remove nginx |
| Update package list | apt update | dnf check-update |
| Upgrade all | apt upgrade | dnf upgrade |
| Search | apt search nginx | dnf search nginx |
| List installed | apt list --installed | dnf list installed |
| Show info | apt show nginx | dnf info nginx |
| Clean cache | apt clean | dnf clean all |
| Auto-remove unused | apt autoremove | dnf autoremove |
Repositories defined in /etc/apt/sources.list (Debian) or /etc/yum.repos.d/ (RHEL)
Prefer system packages (apt/dnf) over compiling from source when possible
| Command | Description | Example |
|---|---|---|
| ps | List processes | ps aux (all processes, detailed) |
| top | Live process monitor | top (q to quit) |
| htop | Better top (interactive) | htop (install if missing) |
| kill | Send signal to process | kill -15 1234 (graceful) |
| kill -9 | Force kill | kill -9 1234 (last resort) |
| killall | Kill by name | killall nginx |
| pkill | Kill by pattern | pkill -f "python app" |
| nice | Start with priority | nice -n 10 command |
| renice | Change running priority | renice -5 -p 1234 |
| nohup | Survive logout | nohup script.sh & |
| bg / fg | Background / foreground | Ctrl+Z then bg |
| jobs | List background jobs | jobs -l |
| & | Run in background | ./script.sh & |
| pgrep | Find PID by name | pgrep nginx |
| Signal | Number | Shortcut | Effect |
|---|---|---|---|
| SIGHUP | 1 | , | Hangup, reload config |
| SIGINT | 2 | Ctrl+C | Interrupt, graceful stop |
| SIGQUIT | 3 | Ctrl+\\ | Quit, core dump |
| SIGKILL | 9 | , | Force kill, cannot be caught |
| SIGTERM | 15 | , | Terminate, graceful (default) |
| SIGSTOP | 19 | Ctrl+Z | Pause process |
| SIGCONT | 18 | , | Resume paused process |
Always try kill -15 (SIGTERM) before kill -9 (SIGKILL)
/proc is a virtual filesystem, files are generated on the fly by the kernel
| Command | Description |
|---|---|
| systemctl start nginx | Start service now |
| systemctl stop nginx | Stop service now |
| systemctl restart nginx | Stop then start |
| systemctl reload nginx | Reload config without downtime |
| systemctl enable nginx | Start on boot |
| systemctl disable nginx | Don't start on boot |
| systemctl status nginx | Show current status and recent logs |
| systemctl is-active nginx | Check if running (returns active/inactive) |
| systemctl is-enabled nginx | Check if enabled at boot |
| systemctl list-units --type=service | List all loaded services |
| systemctl daemon-reload | Reload unit files after changes |
| systemctl mask nginx | Prevent starting (even manually) |
| systemctl unmask nginx | Allow starting again |
Unit files live in /etc/systemd/system/ (custom) or /lib/systemd/system/ (packages)
systemd replaced SysVinit, it is PID 1, the first process, parent of all others
| Target | Equivalent | Purpose |
|---|---|---|
| multi-user.target | Runlevel 3 | CLI multi-user (servers) |
| graphical.target | Runlevel 5 | GUI desktop |
| rescue.target | Runlevel 1 | Single-user, minimal repair |
| emergency.target | , | Root shell only, no services |
| Command | Description | Example |
|---|---|---|
| df | Disk space (filesystem level) | df -h (human-readable) |
| du | Directory disk usage | du -sh /var/log |
| lsblk | List block devices | lsblk -f (with filesystem) |
| fdisk | Partition manager | fdisk -l /dev/sda |
| parted | Advanced partitioning | parted /dev/sda print |
| mkfs | Create filesystem | mkfs.ext4 /dev/sdb1 |
| mount | Attach filesystem | mount /dev/sdb1 /mnt/data |
| umount | Detach filesystem | umount /mnt/data |
| blkid | Show block device UUIDs | blkid /dev/sda1 |
| free | Memory usage (RAM + swap) | free -h |
| swapon | Enable swap | swapon /swapfile |
| Field | Description | Example |
|---|---|---|
| Device | UUID or /dev path | UUID=xxxx-xxxx |
| Mount Point | Where to mount | /mnt/data |
| FS Type | Filesystem | ext4 |
| Options | Mount options | defaults,noatime |
| Dump | Backup flag | 0 (skip) |
| Pass | fsck order | 2 (check after root) |
Always use UUID= instead of /dev/sdX, device names can change on reboot
| Command | Description |
|---|---|
| journalctl | All logs (oldest first) |
| journalctl -u nginx | Logs for specific unit |
| journalctl -f | Follow live logs (tail -f style) |
| journalctl --since "1h ago" | Since a time |
| journalctl --until "2024-01-01" | Until a date |
| journalctl -p err | Only errors and above |
| journalctl -b | Logs from current boot |
| journalctl -b -1 | Logs from previous boot |
| journalctl --no-pager | Output without paging |
| journalctl --disk-usage | Check journal disk usage |
logrotate runs daily via cron (/etc/cron.daily/logrotate)
| Schedule | Crontab |
|---|---|
| Every minute | * * * * * command |
| Every 5 minutes | */5 * * * * command |
| Every hour | 0 * * * * command |
| Every day at midnight | 0 0 * * * command |
| Every Sunday midnight | 0 0 * * 0 command |
| First of every month | 0 0 1 * * command |
| Weekdays at 9 AM | 0 9 * * 1-5 command |
| Every 30 min, 9-5 | */30 9-17 * * * command |
| Command | Description |
|---|---|
| export VAR=value | Set and export to child processes |
| echo $VAR | Print variable value |
| env | Show all environment variables |
| printenv VAR | Print specific variable |
| set | Show all shell variables (env + local) |
| unset VAR | Remove a variable |
Login shell (SSH, console login):
Non-login shell (new terminal tab):
Tip: Put exports in ~/.bashrc and source it from ~/.bash_profile for consistency
| Command | Description | Example |
|---|---|---|
| ip addr | Show IP addresses and interfaces | ip addr show eth0 |
| ip route | Show routing table | ip route show |
| ip link | Manage network interfaces | ip link set eth0 up |
| ss | Socket statistics (connections) | ss -tlnp (TCP listening) |
| ping | Test connectivity (ICMP) | ping -c 4 google.com |
| traceroute | Trace packet path | traceroute google.com |
| dig | DNS lookup (detailed) | dig google.com A |
| nslookup | DNS lookup (simple) | nslookup google.com |
| curl | Transfer data (HTTP, etc.) | curl -I https://example.com |
| wget | Download files | wget https://example.com/file.tar.gz |
| nc (netcat) | TCP/UDP swiss-army knife | nc -zv host 80 (port check) |
| hostname | Show or set hostname | hostnamectl set-hostname web01 |
| nmcli | NetworkManager CLI | nmcli device status |
| Legacy (deprecated) | Modern Replacement |
|---|---|
| ifconfig | ip addr, ip link |
| route | ip route |
| netstat | ss |
| arp | ip neigh |
| traceroute | tracepath (no root needed) |
The ip command from iproute2 replaces ifconfig, route, and arp
| Command | Description |
|---|---|
| ssh user@host | Connect to remote server |
| ssh -p 2222 user@host | Connect on custom port |
| ssh-keygen -t ed25519 | Generate SSH key pair |
| ssh-copy-id user@host | Copy public key to server |
| scp file user@host:/path | Secure copy file to remote |
| sftp user@host | Interactive secure file transfer |
| ssh-agent bash | Start SSH agent |
| ssh-add ~/.ssh/id_ed25519 | Add key to agent |
| ssh -L 8080:localhost:80 host | Local port forwarding (tunnel) |
| ssh -J jump host | SSH via jump host (ProxyJump) |
After editing /etc/ssh/sshd_config, run: systemctl restart sshd
| Table | Purpose | Chains |
|---|---|---|
| filter | Allow/deny packets (default) | INPUT, FORWARD, OUTPUT |
| nat | Network address translation | PREROUTING, OUTPUT, POSTROUTING |
| mangle | Packet header modification | All chains |
| raw | Skip connection tracking | PREROUTING, OUTPUT |
| Command | Description |
|---|---|
| ufw enable | Activate firewall |
| ufw disable | Deactivate firewall |
| ufw status verbose | Show rules and status |
| ufw allow 22 | Allow SSH |
| ufw allow 80/tcp | Allow HTTP (TCP only) |
| ufw deny 3306 | Block MySQL port |
| ufw allow from 10.0.0.0/8 | Allow from subnet |
| ufw delete allow 80 | Remove a rule |
| ufw reset | Reset to defaults |
UFW is a user-friendly frontend for iptables, ideal for Ubuntu servers
| Command | Description |
|---|---|
| firewall-cmd --state | Check if running |
| firewall-cmd --list-all | Show all rules |
| firewall-cmd --add-service=http | Allow HTTP |
| firewall-cmd --add-port=8080/tcp | Allow port 8080 |
| firewall-cmd --remove-port=8080/tcp | Remove port rule |
| firewall-cmd --reload | Apply pending changes |
| firewall-cmd --zone=public --list-all | Show zone rules |
| --permanent | Persist across reboots (add to any cmd) |
| Feature | iptables | UFW | firewalld |
|---|---|---|---|
| Complexity | High | Low | Medium |
| Distro | Any | Debian/Ubuntu | RHEL/CentOS/Fedora |
| Zones | No | No | Yes |
| Live reload | Immediate | Immediate | --reload needed |
| Backend | Kernel netfilter | iptables | nftables / iptables |
| Tool | Purpose | Example |
|---|---|---|
| grep | Search text by pattern | grep "error" /var/log/syslog |
| sed | Stream editor (find/replace) | sed 's/old/new/g' file |
| awk | Column processing & reporting | awk '(print $1, $3)' file |
| cut | Extract fields / columns | cut -d: -f1 /etc/passwd |
| sort | Sort lines | sort -t: -k3 -n /etc/passwd |
| uniq | Remove duplicate lines | sort file | uniq -c |
| tr | Translate or delete chars | echo HELLO | tr A-Z a-z |
| xargs | Build commands from stdin | find . -name "*.log" | xargs rm |
| tee | Write to file and stdout | echo hi | tee log.txt |
| Flag | Description |
|---|---|
| -i | Case insensitive search |
| -r | Recursive (search all files in dir) |
| -n | Show line numbers |
| -v | Invert match (lines NOT matching) |
| -c | Count matching lines |
| -l | Show only filenames with matches |
| -E | Extended regex (egrep) |
| -w | Match whole words only |
| -A 3 | Show 3 lines after match |
| -B 3 | Show 3 lines before match |
grep -rn "TODO" ., recursively find all TODOs with line numbers
| Command | Description |
|---|---|
| sed 's/old/new/' | Replace first occurrence per line |
| sed 's/old/new/g' | Replace all occurrences |
| sed -i 's/old/new/g' file | In-place edit (modify file) |
| sed '/pattern/d' | Delete lines matching pattern |
| sed -n '5,10p' | Print only lines 5β10 |
| sed '3i\new text' | Insert text before line 3 |
| sed '3a\new text' | Append text after line 3 |
Always test without -i first, then add -i to modify in place
Pipe chain example:
cat access.log | awk '(print $1)' | sort | uniq -c | sort -rn | head -10
This gets the top 10 IP addresses from an access log
| Structure | Syntax |
|---|---|
| if | if [ condition ]; then ... elif ...; then ... else ... fi |
| for | for i in 1 2 3; do echo $i; done |
| for (C-style) | for ((i=0; i<10; i++)); do echo $i; done |
| while | while [ condition ]; do ... done |
| until | until [ condition ]; do ... done |
| case | case $VAR in pattern1) cmd;; pattern2) cmd;; esac |
| function | my_func() ( echo "hello"; ), define reusable block |
Test conditions: [ -f file ] (file exists), [ -d dir ] (dir exists), [ -z "$str" ] (empty string)
| Category | Command | Description |
|---|---|---|
| Navigation | pwd | Print working directory |
| ls -la | List all files with details | |
| cd /path | Change directory | |
| find / -name "file" | Find files by name | |
| tree -L 2 | Show directory tree | |
| Files | cp -r src dest | Copy files/directories |
| mv old new | Move or rename | |
| rm -rf dir | Remove directory (caution!) | |
| cat / less / head / tail | View file contents | |
| tar -czf archive.tar.gz dir/ | Create compressed archive | |
| Permissions | chmod 755 file | Change file mode |
| chown user:group file | Change owner and group | |
| umask 022 | Set default permissions | |
| ls -la | View permissions | |
| Users | useradd -m user | Create user with home dir |
| passwd user | Set user password | |
| usermod -aG group user | Add user to group | |
| sudo command | Run as superuser | |
| Packages | apt update && apt upgrade | Update packages (Debian) |
| apt install pkg | Install package (Debian) | |
| dnf install pkg | Install package (RHEL) | |
| apt search pkg | Search packages | |
| Processes | ps aux | List all processes |
| top / htop | Live process monitor | |
| kill -15 PID | Gracefully stop process | |
| kill -9 PID | Force kill process | |
| systemctl status service | Check service status | |
| Network | ip addr | Show IP addresses |
| ss -tlnp | Show listening ports | |
| ping host | Test connectivity | |
| curl -I url | HTTP headers check | |
| dig domain | DNS lookup | |
| Disk | df -h | Disk space usage |
| du -sh dir/ | Directory size | |
| lsblk | List block devices | |
| free -h | Memory usage | |
| Logs | journalctl -u service | View service logs |
| tail -f /var/log/syslog | Follow live logs | |
| dmesg | tail | Recent kernel messages | |
| Services | systemctl start service | Start a service |
| systemctl enable service | Enable at boot | |
| systemctl restart service | Restart a service | |
| systemctl daemon-reload | Reload unit files | |
| SSH | ssh user@host | Connect to remote server |
| ssh-keygen -t ed25519 | Generate SSH key pair | |
| scp file user@host:/path | Secure copy to remote |