Bash and Linux 5 cheatsheet

Bash and Linux 5: Processes and system

11 common Bash and Linux 5 tasks.

List processes

Show every running process with its owner and resource use.

ps aux

Find a process by name

Search the process list for a name.

ps aux | grep nginx

Stop a process

Ask a process to terminate gracefully using its PID.

kill 1234

Force-kill a process

End a process immediately when it ignores a normal kill.

kill -9 1234

Caution: The process cannot clean up, so data can be lost. Try plain kill first.

Find what is using a port

List the process listening on a port.

lsof -i :3000

Check free disk space

Show space on each mounted filesystem in readable units.

df -h

Find what is using space

Show the size of each item in the current folder, largest last.

du -sh * | sort -h

Check memory

Show used and free memory.

free -h

Check a service

Show whether a systemd service is running.

systemctl status nginx

Follow a service's logs

Stream the journal for a systemd unit.

journalctl -u nginx -f

Set an environment variable

Make a variable available to programs started from this shell.

export API_URL=http://localhost:8000

Was this page helpful?