Toolbox · Systems
Linux Commands
Process, disk, memory, file and service inspection for production hosts.
On this page
Processes and load
| Command | Purpose |
|---|---|
uptime | Load averages (1/5/15 min) |
top -o %MEM / htop | Live process view |
ps -eo pid,ppid,user,%cpu,%mem,etime,cmd --sort=-%cpu | head | Top CPU consumers |
pgrep -af nginx | Find processes by name |
strace -f -p <pid> -e trace=network | Trace syscalls of a running process |
lsof -p <pid> | Open files/sockets of a process |
kill -TERM <pid> then kill -KILL <pid> | Graceful, then forced |
Memory and disk
| Command | Purpose |
|---|---|
free -h | Memory incl. cache/buffers |
vmstat 1 5 | Paging, IO wait, context switches |
df -hT | Filesystem usage |
du -xsh /var/* 2>/dev/null | sort -h | tail | What is filling the disk |
lsof +L1 | Deleted-but-open files holding space |
iostat -xz 1 3 | Disk latency and utilisation |
dmesg -T | tail -50 | Kernel messages (OOM killer, disk errors) |
Files and text
| Command | Purpose |
|---|---|
find /var/log -name '*.log' -mtime -1 -size +50M | Recent large logs |
grep -rn --include='*.conf' 'listen' /etc/nginx | Recursive search |
tail -F /var/log/app.log | Follow, survive rotation |
journalctl -u nginx -f --since "10 min ago" | Service logs |
sed -n '120,140p' file | Print a line range |
awk -F: '$3 >= 1000 {print $1}' /etc/passwd | Human users |
stat -c '%U:%G %a %n' /etc/ssh/sshd_config | Owner and mode |
Services and boot
| Command | Purpose |
|---|---|
systemctl status nginx | State and recent logs |
systemctl list-units --failed | Failed units |
systemctl cat nginx | Effective unit file |
systemd-analyze blame | Slow boot units |
Users and permissions
| Command | Purpose |
|---|---|
id user / groups user | Identity |
last -n 20 / lastlog | Logins |
sudo -l -U user | Sudo rights |
chmod 600 file / chown app:app file | Permissions |
getfacl file | ACLs |