Same Linux, Different Commands
Linux is not a single entity. Distributions like Ubuntu, CentOS/RHEL, Alpine, and Arch each have different package managers and service management commands. Since managing multiple distributions simultaneously is common in server operations, understanding the differences between them is important.
This article organizes frequently used commands by category and compares the differences between major distributions.
Major Distributions and Package Managers
| Distribution Family | Representative Distros | Package Manager | Package Format | Use Case |
|---|---|---|---|---|
| Debian family | Ubuntu, Debian | apt | .deb | Server, desktop |
| Red Hat family | RHEL, CentOS, Rocky, Alma | dnf (formerly yum) | .rpm | Enterprise server |
| Alpine | Alpine Linux | apk | .apk | Docker containers |
| Arch family | Arch, Manjaro | pacman | .pkg.tar.zst | Desktop, latest packages |
Package Management
This is where the biggest differences lie. Even identical operations require completely different commands depending on the distribution.
# === Package installation ===
# Debian/Ubuntu
sudo apt update && sudo apt install -y nginx
# RHEL/CentOS/Rocky (8+)
sudo dnf install -y nginx
# Alpine
apk add nginx
# Arch
sudo pacman -S nginx
# === Package search ===
# Debian/Ubuntu
apt search nginx
# RHEL/CentOS
dnf search nginx
# Alpine
apk search nginx
# Arch
pacman -Ss nginx
| Task | apt (Debian/Ubuntu) | dnf (RHEL/CentOS) | apk (Alpine) | pacman (Arch) |
|---|---|---|---|---|
| Update repos | apt update | dnf check-update | apk update | pacman -Sy |
| Install package | apt install pkg | dnf install pkg | apk add pkg | pacman -S pkg |
| Remove package | apt remove pkg | dnf remove pkg | apk del pkg | pacman -R pkg |
| Full upgrade | apt upgrade | dnf upgrade | apk upgrade | pacman -Syu |
| List installed | apt list --installed | dnf list installed | apk info | pacman -Q |
| Search packages | apt search keyword | dnf search keyword | apk search keyword | pacman -Ss keyword |
| Clean cache | apt clean | dnf clean all | apk cache clean | pacman -Sc |
Service Management (systemctl)
Most modern distributions use systemd, so the systemctl command is common. The exception is Alpine, which uses OpenRC as its default init system.
# === systemd-based (Ubuntu, CentOS, Arch, etc. — most distros) ===
sudo systemctl start nginx # Start service
sudo systemctl stop nginx # Stop service
sudo systemctl restart nginx # Restart
sudo systemctl status nginx # Check status
sudo systemctl enable nginx # Enable auto-start on boot
sudo systemctl disable nginx # Disable auto-start
# === OpenRC (Alpine Linux) ===
rc-service nginx start # Start service
rc-service nginx stop # Stop service
rc-service nginx restart # Restart
rc-service nginx status # Check status
rc-update add nginx default # Enable auto-start on boot
rc-update del nginx default # Disable auto-start
| Task | systemd (most distros) | OpenRC (Alpine) |
|---|---|---|
| Start | systemctl start svc | rc-service svc start |
| Stop | systemctl stop svc | rc-service svc stop |
| Status | systemctl status svc | rc-service svc status |
| Auto-start | systemctl enable svc | rc-update add svc default |
| View logs | journalctl -u svc | cat /var/log/svc.log |
Common Essential Commands
Aside from package and service management, most commands are identical regardless of distribution.
Files and Directories
# File list (detailed, including hidden, human-readable sizes)
ls -lah
# Navigate / create / delete directories
cd /var/log
mkdir -p /opt/app/config # Automatically create intermediate directories
rm -rf /tmp/old-build # Force delete (use with caution!)
# Copy / move / rename files
cp config.yaml config.yaml.bak
mv old-name.txt new-name.txt
# View file contents
cat /etc/hostname # Full output
head -20 /var/log/syslog # First 20 lines
tail -f /var/log/nginx/access.log # Follow logs in real time
# Find files
find /var/log -name "*.log" -mtime +30 -type f # .log files older than 30 days
Text Processing
# grep: text search
grep -rn "error" /var/log/app/ # Recursive search + line numbers
grep -i "warning" app.log # Case-insensitive
# awk: column-based processing
df -h | awk '{print $1, $5}' # Extract disk usage percentage only
# /dev/sda1 42%
# sed: text substitution
sed -i 's/localhost/0.0.0.0/g' config.yaml # Replace string in file
# wc: line/word/byte count
wc -l /var/log/syslog # Count lines
# sort + uniq: sort then deduplicate
cat access.log | awk '{print $1}' | sort | uniq -c | sort -rn | head -10
# Top 10 IPs by access count
System Monitoring
# Disk usage
df -h # Usage by filesystem
du -sh /var/log/* # Size per directory
# Memory usage
free -h # Total/used/free memory
# total: 16Gi, used: 8.2Gi, free: 2.1Gi, available: 7.3Gi
# CPU / processes
top # Real-time process monitor
htop # Improved version of top (requires installation)
ps aux | grep nginx # Search for specific process
# Network
ss -tlnp # Check open ports (replaces netstat)
curl -I https://example.com # Check HTTP headers
ping -c 4 8.8.8.8 # Test network connectivity
| Command | Purpose | Common Options |
|---|---|---|
df -h | Disk usage | -h human-readable units |
free -h | Memory usage | -h human-readable units |
top / htop | Real-time processes | htop recommended (colors, mouse support) |
ss -tlnp | Open ports | -t TCP, -l listen, -n numeric, -p process |
journalctl | System logs | -u svc per service, -f real-time |
Users and Permissions
# Add/remove users
sudo useradd -m -s /bin/bash deploy # Create home directory + set default shell
sudo passwd deploy # Set password
sudo userdel -r deploy # Delete user + home directory
# Group management
sudo usermod -aG docker deploy # Add deploy user to docker group
# File permissions
chmod 755 script.sh # rwxr-xr-x
chmod 600 .env # rw------- (owner read/write only)
chown deploy:deploy /opt/app -R # Change owner/group (recursive)
| Permission Number | Meaning | Common Use |
|---|---|---|
755 | rwxr-xr-x | Executables, directories |
644 | rw-r—r— | Regular files, config files |
600 | rw------- | Private keys, .env files |
700 | rwx------ | .ssh directories |
Summary
The key takeaway about Linux commands is that only the package manager differs by distribution — everything else is largely the same.
- Package management:
apt(Ubuntu) vsdnf(RHEL) vsapk(Alpine) vspacman(Arch) - Service management:
systemctlfor most, only Alpine usesrc-service/rc-update - File/text/system commands:
ls,grep,find,df,free, etc. are common across all distributions - Most frequently used combinations in server operations:
tail -f(logs),grep -rn(search),df -h(disk),ss -tlnp(ports) - Permission management: Protect sensitive files with
chmod 600, set ownership withchown