NewCode CLOUD — 20% off your first month on all cloud VPSClaim

Comparison of System Commands in CentOS and Ubuntu

· 4 min read

CentOS and Ubuntu, two prominent Linux distributions based on Red Hat (RPM ecosystem) and Debian (DEB ecosystem) respectively, exhibit notable differences in system management commands. This document provides a technical comparison of their commonly used commands across package management, service management, network configuration, firewall, user management, file system, and log management. It aims to assist administrators and developers in quickly mastering and efficiently switching between these systems.

1. Package Management

Package management is a core distinction between CentOS and Ubuntu. CentOS uses yum or dnf (CentOS 8 and later), while Ubuntu uses apt.

Function CentOS (RPM Ecosystem) Ubuntu (DEB Ecosystem)
Update Package List sudo yum check-update or sudo dnf check-update sudo apt update
Install Package sudo yum install <package> or sudo dnf install <package> sudo apt install <package>
Remove Package sudo yum remove <package> or sudo dnf remove <package> sudo apt remove <package>
Search Package sudo yum search <keyword> or sudo dnf search <keyword> sudo apt search <keyword>
Update All Installed Packages sudo yum update or sudo dnf upgrade sudo apt upgrade
Clear Cache sudo yum clean all or sudo dnf clean all sudo apt clean
List Installed Packages rpm -qa or yum list installed or dnf list installed dpkg -l or apt list –installed

Notes:

  • CentOS 8 and later use dnf by default, which shares similar syntax with yum but offers improved performance.
  • Ubuntu’s apt is a high-level wrapper for apt-get and apt-cache, optimized for interactive use.

2. Service Management

CentOS 7 and Ubuntu 16.04 and later both use systemd as their service management framework, resulting in highly consistent commands.

Function CentOS (Systemd) Ubuntu (Systemd)
Start Service sudo systemctl start <service> sudo systemctl start <service>
Stop Service sudo systemctl stop <service> sudo systemctl stop <service>
Restart Service sudo systemctl restart <service> sudo systemctl restart <service>
Check Service Status sudo systemctl status <service> sudo systemctl status <service>
Enable Service on Boot sudo systemctl enable <service> sudo systemctl enable <service>
Disable Service on Boot sudo systemctl disable <service> sudo systemctl disable <service>
List All Services systemctl list-unit-files –type=service systemctl list-unit-files –type=service

Notes:

  • CentOS 6 and earlier use SysVinit, with commands like service <service> start/stop/restart.
  • Ubuntu 14.04 and earlier partially use Upstart, requiring attention to compatibility with older versions.

3. Network Management

Network management commands differ due to distinct configuration approaches. CentOS relies on NetworkManager or manual configuration files, while Ubuntu uses Netplan (18.04 and later).

Function CentOS Ubuntu
Check IP Address ip addr or ifconfig ip addr or ifconfig
Restart Network Service sudo systemctl restart NetworkManager sudo systemctl restart networking or sudo netplan apply
Check Network Interface Status nmcli device status nmcli device status
Configure Static IP Edit /etc/sysconfig/network-scripts/ifcfg-<interface> Edit /etc/netplan/01-netcfg.yaml, then sudo netplan apply

Notes:

  • Ubuntu 18.04 and later use Netplan, with YAML configuration files requiring proper indentation.
  • CentOS network configuration file paths may vary by version, so verify the specific interface file.

4. Firewall Management

CentOS uses firewalld by default, while Ubuntu uses ufw (a simplified iptables frontend).

Function CentOS (Firewalld) Ubuntu (UFW)
Start Firewall sudo systemctl start firewalld sudo ufw enable
Stop Firewall sudo systemctl stop firewalld sudo ufw disable
Check Firewall Status sudo firewall-cmd –state sudo ufw status
Open Port sudo firewall-cmd –add-port=<port>/tcp –permanent sudo ufw allow <port>
Close Port sudo firewall-cmd –remove-port=<port>/tcp –permanent sudo ufw delete allow <port>
Reload Firewall Configuration sudo firewall-cmd –reload sudo ufw reload

Notes:

  • firewalld’s –permanent option ensures rules persist, requiring –reload to take effect.
  • ufw is user-friendly and suitable for lightweight configurations but less feature-rich than firewalld.

5. User and Permission Management

User management commands are largely consistent, with minor differences in user deletion.

Function CentOS Ubuntu
Add User sudo adduser <username> sudo adduser <username>
Delete User sudo userdel -r <username> sudo deluser –remove-home <username>
Change User Password sudo passwd <username> sudo passwd <username>
Add User to Group sudo usermod -aG <group> <username> sudo usermod -aG <group> <username>

Notes:

  • userdel -r and deluser –remove-home both remove the user’s home directory; use with caution.
  • Group management commands are identical, with -aG ensuring group appending rather than overwriting.

6. File System Management

File system management commands are consistent, though default file systems may differ (CentOS prefers xfs, Ubuntu prefers ext4).

Function CentOS Ubuntu
Check Disk Space df -h df -h
Check Directory Size du -sh <directory> du -sh <directory>
Mount File System mount /dev/sdX /mnt mount /dev/sdX /mnt
Unmount File System umount /mnt umount /mnt

Notes:

  • Mounting requires the target device and mount point to exist.
  • Use lsblk to check device status.

7. Log Management

Log management commands are mostly consistent, but log file paths differ.

Function CentOS Ubuntu
View System Logs sudo journalctl or tail -f /var/log/messages sudo journalctl or tail -f /var/log/syslog
View Login Logs last last

Notes:

  • CentOS’s /var/log/messages may be /var/log/secure depending on configuration.
  • Ubuntu’s /var/log/syslog is the default system log path.

Summary

Aspect CentOS Ubuntu
Package Management yum/dnf (RPM) apt (DEB)
Service Management systemctl (CentOS 7+), service (older) systemctl (16.04+), Upstart (older)
Firewall firewalld ufw
Network Configuration /etc/sysconfig/network-scripts/ /etc/netplan/ (18.04 and later)

By understanding these differences, administrators and developers can quickly adapt to the system management requirements of CentOS and Ubuntu, enhancing operational efficiency.

Related articles

More in Setup & TutorialsServer setup guides