
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.
1. Navigation
| Command | What it does |
|---|---|
pwd | Show the current directory |
ls -lah | List files with sizes, permissions and hidden files |
cd /var/log | Change directory (cd ~ home, cd - previous, cd .. up) |
tree -L 2 | Show folders as a tree (install with dnf install tree) |
find / -name "*.conf" 2>/dev/null | Find files by name |
2. File management
| Command | What it does |
|---|---|
mkdir -p /srv/app/logs | Create directories, including parents |
cp -a src/ dest/ | Copy, keeping permissions and timestamps |
mv old.txt new.txt | Move or rename |
rm file / rm -r dir | Delete a file / a directory (no recycle bin!) |
cat, less, head, tail -f | View files; tail -f follows a growing log |
nano file / vi file | Edit a file |
grep -Ri "error" /var/log | Search text inside files |
tar -czf backup.tar.gz dir/ | Create a compressed archive (-xzf to extract) |
3. System information
| Command | What it does |
|---|---|
cat /etc/os-release | Distribution and version |
uname -r | Kernel version |
hostnamectl | Host name, OS, kernel, virtualization |
uptime | Running time and load average |
free -h | Memory and swap use |
df -h / du -sh * | Disk space per file system / per folder |
lscpu, lsblk | CPU 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).
| Command | What it does |
|---|---|
sudo dnf update | Update all packages |
sudo dnf install nginx | Install a package |
sudo dnf remove nginx | Remove a package |
dnf search php | Search for packages |
dnf list installed | List installed packages |
dnf provides /usr/bin/dig | Find which package provides a file |
sudo dnf install epel-release | Enable EPEL for extra packages |
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
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
| Command | What it does |
|---|---|
ip a | Show IP addresses |
ip r | Show routes and default gateway |
ss -tulpn | Listening ports and the programs using them |
ping -c 4 8.8.8.8 | Test connectivity |
curl -I https://example.com | Fetch HTTP headers |
nmcli con show | NetworkManager connections |
sudo firewall-cmd --list-all | Firewall rules (firewalld) |
sudo firewall-cmd --permanent --add-port=8080/tcp && sudo firewall-cmd --reload | Open 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.


