Essential Linux Commands Guide: Comparison by Distribution

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 FamilyRepresentative DistrosPackage ManagerPackage FormatUse Case
Debian familyUbuntu, Debianapt.debServer, desktop
Red Hat familyRHEL, CentOS, Rocky, Almadnf (formerly yum).rpmEnterprise server
AlpineAlpine Linuxapk.apkDocker containers
Arch familyArch, Manjaropacman.pkg.tar.zstDesktop, 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
Taskapt (Debian/Ubuntu)dnf (RHEL/CentOS)apk (Alpine)pacman (Arch)
Update reposapt updatednf check-updateapk updatepacman -Sy
Install packageapt install pkgdnf install pkgapk add pkgpacman -S pkg
Remove packageapt remove pkgdnf remove pkgapk del pkgpacman -R pkg
Full upgradeapt upgradednf upgradeapk upgradepacman -Syu
List installedapt list --installeddnf list installedapk infopacman -Q
Search packagesapt search keyworddnf search keywordapk search keywordpacman -Ss keyword
Clean cacheapt cleandnf clean allapk cache cleanpacman -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
Tasksystemd (most distros)OpenRC (Alpine)
Startsystemctl start svcrc-service svc start
Stopsystemctl stop svcrc-service svc stop
Statussystemctl status svcrc-service svc status
Auto-startsystemctl enable svcrc-update add svc default
View logsjournalctl -u svccat /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
CommandPurposeCommon Options
df -hDisk usage-h human-readable units
free -hMemory usage-h human-readable units
top / htopReal-time processeshtop recommended (colors, mouse support)
ss -tlnpOpen ports-t TCP, -l listen, -n numeric, -p process
journalctlSystem 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 NumberMeaningCommon Use
755rwxr-xr-xExecutables, directories
644rw-r—r—Regular files, config files
600rw-------Private keys, .env files
700rwx------.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) vs dnf (RHEL) vs apk (Alpine) vs pacman (Arch)
  • Service management: systemctl for most, only Alpine uses rc-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 with chown

Was this article helpful?