Skip to content

Linux commands for server admins

Disk, memory, processes, services, logs and networking: the commands used every day on a Linux server.

6
Sections
2 min
Read time

Disk and memory

CommandWhat it shows
df -hFree and used space on each disk
du -sh /var/www/*Size of each folder
free -hMemory and swap usage
lsblkDisks and partitions

Processes and load

CommandWhat it does
top or htopLive view of CPU, memory and processes
uptimeLoad average for 1, 5 and 15 minutes
ps aux --sort=-%memProcesses sorted by memory use
kill PIDAsk a process to stop

Services (systemd)

CommandWhat it does
systemctl status nginxIs the service running, and its latest log lines
systemctl restart nginxRestart a service
systemctl enable nginxStart it automatically at boot
systemctl --failedList services that failed

Logs

CommandWhat it does
journalctl -u nginx -n 100Last 100 log lines of a service
journalctl -fFollow the system log live
tail -f /var/log/nginx/error.logFollow a log file live

Network

CommandWhat it does
ip aIP addresses of the server
ss -tulpnWhich ports are listening, and by which program
ping example.comIs a host reachable, and how fast
dig example.com AAsk DNS for a record
curl -I https://example.comFetch only the response headers

Files and permissions

CommandWhat it does
ls -lahList files with sizes, owners and permissions
chown -R www-data:www-data dirChange the owner of a folder
chmod 640 fileSet file permissions
find /var/www -mtime -2 -type fFiles changed in the last two days
tar -czf backup.tar.gz dirCompress a folder into an archive

Read a command twice before running it as root, especially anything with rm -r, chmod -R or chown -R.