Skip to content
gohacks.dev
Tooling

Linux Commands Cheat Sheet

The Linux commands a server needs most, searchable by task: disk and memory, processes and ports, services and logs, files and permissions, networking, users and packages.

Free · No sign-up · Your inputs stay in your browser

Reference

Linux commands for servers

CommandDoesNotes
df -hDisk space per filesystemdf -i shows inodes, which run out before bytes on a disk of tiny files.
du -sh * | sort -hSize of each item here, sortedncdu is the interactive version.
free -hMemory and swapLook at available, not free: cache counts as available.
uptimeLoad averages for 1, 5 and 15 minutesCompare with the core count from nproc.
top / htopLive processesIn top, press M to sort by memory and P by CPU.
ps aux --sort=-%mem | headBiggest memory users
ss -tulpnListening ports and the processes behind themReplaces netstat -tulpn.
lsof -i :8080What is using a port
journalctl -u nginx -fFollow a service's log-p err for errors only, --since '1 hour ago'.
systemctl status nginxService state and last log linesrestart, reload, enable --now, disable.
systemctl list-units --failedUnits that failed
tail -f /var/log/syslogFollow a log filetail -F keeps following across log rotation.
grep -rn 'pattern' /etc/nginxSearch files recursively with line numbers-i ignores case, -l lists file names only.
find / -xdev -size +500M -type fFind large files on this filesystem
chmod 640 file / chown www-data:www-data filePermissions and ownership-R for recursive; be careful at /.
tar -czf backup.tgz dir/ / tar -xzf backup.tgzCreate and extract a gzip tarball
rsync -avz --progress src/ user@host:/dst/Copy efficiently, locally or over SSHTrailing slash on src copies its contents.
scp file user@host:/path/Copy a file over SSHrsync is better for anything large or repeated.
ssh -L 5433:localhost:5432 user@hostForward a remote port locallyReach a database that only listens on localhost.
curl -sSI https://example.comResponse headers only-v shows the TLS handshake and request.
dig +short example.com AResolve a name@1.1.1.1 to ask a specific resolver.
ip -br addr / ip routeAddresses and routesReplace ifconfig and route.
mtr example.comTraceroute and ping combinedShows where packet loss starts.
dmesg -T | tailKernel messages with timesWhere the OOM killer reports what it killed.
last -a | head / whoRecent and current logins
crontab -e / crontab -lEdit or list your cron jobssudo crontab -u www-data -l for another user.
usermod -aG docker deployAdd a user to a group-a is essential: without it the user leaves every other group.
sudo -u www-data php artisan ...Run a command as another user
watch -n 2 'command'Re-run a command every 2 seconds
nohup cmd > out.log 2>&1 &Keep a command running after logouttmux or a systemd unit is better for anything that matters.
openssl s_client -connect host:443 -servername hostInspect a TLS endpoint
timedatectl / hostnamectlClock, time zone and host nametimedatectl set-timezone UTC.
apt list --upgradable / dnf check-updatePending package updates

The commands a server needs most, as on current Debian, Ubuntu and RHEL-family systems with systemd. Prefix with sudo where the target belongs to root. man command, or tldr command for examples, has the rest.

For systemd distributions

The commands match current Debian, Ubuntu, RHEL, Rocky and Alma Linux, which all use systemd and iproute2; older tools such as netstat and ifconfig are replaced by ss and ip. man and tldr pages cover every command in detail; the Linux man-pages project publishes them online.

The order of investigation

When a server misbehaves: uptime for load, free for memory, df for disk, journalctl and dmesg for errors, ss for what is listening, then top or htop for the process responsible. Most incidents show up in the first three.

Share

Frequently asked questions

How do I see what is using a port on Linux?
sudo ss -tulpn shows listening sockets with the owning process; sudo lsof -i :8080 shows everything using port 8080.
How do I find what is filling the disk?
du -sh /* | sort -h, then repeat in the largest directory, or use ncdu for an interactive view. Check deleted-but-open files with lsof +L1.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools