Since 2016 · 50,000+ customers · ★ 5.0 on Google Live chatWhatsAppTelegramOpen a ticket
Get started
Linux

Basic CentOS Commands Cheat Sheet (Also for AlmaLinux and Rocky)

Basic CentOS commands cheat sheet by 99RDP

Managing a CentOS server comes down to a few dozen commands you'll use every day: moving around the file system, editing files, installing packages, managing services, users, permissions, networking and processes. This cheat sheet groups the essentials with short examples. Everything here works the same on AlmaLinux, Rocky Linux and RHEL, the successors to CentOS, with one difference noted for package management.

Quick answerThe ten commands you'll use most are ls, cd, cp, mv, rm, nano/vi, dnf (or yum), systemctl, firewall-cmd and journalctl.

Before you start: CentOS versions

CentOS Linux 7 reached end of life in June 2024 and CentOS Linux 8 in December 2021. Most servers now run AlmaLinux or Rocky Linux 9 or 10, or CentOS Stream. Use cat /etc/os-release to see which one you're on.

Diagram of the RHEL family: Fedora, CentOS Stream, RHEL, and the AlmaLinux and Rocky Linux rebuilds
Where CentOS fits today
CommandWhat it does
pwdShow the current directory
ls -lahList files with sizes, permissions and hidden files
cd /var/logChange directory (cd ~ home, cd - previous, cd .. up)
tree -L 2Show folders as a tree (install with dnf install tree)
find / -name "*.conf" 2>/dev/nullFind files by name

2. File management

CommandWhat it does
mkdir -p /srv/app/logsCreate directories, including parents
cp -a src/ dest/Copy, keeping permissions and timestamps
mv old.txt new.txtMove or rename
rm file / rm -r dirDelete a file / a directory (no recycle bin!)
cat, less, head, tail -fView files; tail -f follows a growing log
nano file / vi fileEdit a file
grep -Ri "error" /var/logSearch text inside files
tar -czf backup.tar.gz dir/Create a compressed archive (-xzf to extract)

3. System information

CommandWhat it does
cat /etc/os-releaseDistribution and version
uname -rKernel version
hostnamectlHost name, OS, kernel, virtualization
uptimeRunning time and load average
free -hMemory and swap use
df -h / du -sh *Disk space per file system / per folder
lscpu, lsblkCPU details, disks and partitions

4. Package management

CentOS 7 uses yum; CentOS Stream, AlmaLinux and Rocky Linux 8+ use dnf (and yum still works as an alias).

CommandWhat it does
sudo dnf updateUpdate all packages
sudo dnf install nginxInstall a package
sudo dnf remove nginxRemove a package
dnf search phpSearch for packages
dnf list installedList installed packages
dnf provides /usr/bin/digFind which package provides a file
sudo dnf install epel-releaseEnable EPEL for extra packages
Diagram of the dnf workflow: search, install, update and remove packages on CentOS and Rocky Linux
The dnf package cycle

5. Services (systemd)

sudo systemctl start nginx         # start now
sudo systemctl enable --now nginx  # start now and at boot
sudo systemctl restart nginx
sudo systemctl status nginx
systemctl list-units --type=service --state=running
journalctl -u nginx -n 50          # last 50 log lines for a service
journalctl -f                      # follow the system log
Table of systemctl commands that start, stop, enable and check a service
Controlling services with systemctl

6. Users and groups

sudo useradd -m alice && sudo passwd alice   # create a user and set password
sudo usermod -aG wheel alice                 # give sudo rights (wheel group)
id alice                                     # user's groups
sudo userdel -r alice                        # delete user and home directory
su - alice                                   # switch user

7. File permissions

chmod 644 file.txt        # owner rw, others r
chmod 755 script.sh       # owner rwx, others rx
chmod +x script.sh        # make executable
sudo chown alice:alice file.txt
sudo chown -R nginx:nginx /var/www/site

If a web server still can't read files with correct permissions, check SELinux labels with ls -Z and fix them with restorecon -Rv /path.

8. Networking

CommandWhat it does
ip aShow IP addresses
ip rShow routes and default gateway
ss -tulpnListening ports and the programs using them
ping -c 4 8.8.8.8Test connectivity
curl -I https://example.comFetch HTTP headers
nmcli con showNetworkManager connections
sudo firewall-cmd --list-allFirewall rules (firewalld)
sudo firewall-cmd --permanent --add-port=8080/tcp && sudo firewall-cmd --reloadOpen a port

9. Processes

top                     # live view (or htop / btop if installed)
ps aux | grep nginx     # find a process
kill 1234               # stop a process by PID (kill -9 to force)
pkill -f myscript.py    # stop by name
nohup ./job.sh &        # keep running after logout

10. Disks and logs

sudo du -xh / --max-depth=1 | sort -h   # what uses disk space
sudo journalctl --disk-usage             # size of the system journal
sudo journalctl --vacuum-time=7d         # keep only 7 days of logs
sudo tail -f /var/log/messages           # classic system log

Frequently asked questions

What are the basic CentOS commands?

Navigation (ls, cd, pwd), files (cp, mv, rm), packages (yum/dnf), services (systemctl), firewall (firewall-cmd) and logs (journalctl).

Is it yum or dnf on CentOS?

yum on CentOS 7; dnf on CentOS Stream, AlmaLinux and Rocky Linux 8 and later, where yum is an alias for dnf.

How do I give a user sudo rights on CentOS?

Add them to the wheel group: sudo usermod -aG wheel username.

Do these commands work on AlmaLinux and Rocky Linux?

Yes. They're binary-compatible with RHEL and use the same commands as CentOS.

Nishant Kumar, Sr. Server Engineer at 99RDP
Written byNishant KumarSr. Server Engineer, 99RDP. Part of the team that runs our servers and answers support.
Keep reading

More Linux guides

All Linux guides

Need a server for this?

✓ Setup in minutes✓ Full admin access✓ 7-day refund on new services