Skip to content

Linux commands cheat sheet

Everyday shell commands for Linux (and mostly macOS). Works in bash and zsh.

27 entries

Permissions

chmod +x deploy.sh
chmod 644 file.txt

Make executable; rw-r--r--.

chown -R www-data:www-data /var/www

Change owner and group recursively.

sudo !!

Re-run the last command with sudo.

Text processing

sort names.txt | uniq -c | sort -nr

Count duplicate lines, most frequent first.

cut -d, -f2 data.csv

Second comma-separated column.

awk '{print $1}' access.log

First whitespace-separated field.

sed -i 's/foo/bar/g' file.txt

Replace in place (macOS: sed -i '').

wc -l file.txt

Count lines.

Processes & system

ps aux | grep node
top   # or htop

List processes; live monitor.

kill 1234
kill -9 1234
pkill -f "python app.py"

Stop by PID (TERM, then KILL); by name.

command &
jobs
fg %1

Background a job and bring it back.

df -h
du -sh *
free -h

Disk space, folder sizes, memory.

systemctl status nginx
journalctl -u nginx -f

Service status and logs (systemd).

Network

curl -I https://example.com
curl -s api/url | jq .

Headers; fetch JSON and pretty-print.

ss -tulpn

Listening ports and owning processes.

ping -c 4 example.com
dig example.com +short

Reachability; DNS lookup.

ssh user@host
scp file user@host:/tmp/

Remote shell; copy a file.

Archives

tar -czf site.tar.gz site/
tar -xzf site.tar.gz

Create / extract a gzipped tarball.

zip -r out.zip dir/
unzip out.zip

Zip files.

Frequently asked questions

How do I find which process is using a port?

Run ss -tulpn | grep :8080 (or lsof -i :8080). The output shows the process name and PID.

What does chmod 755 mean?

Owner can read, write and execute (7); group and others can read and execute (5). It is the usual mode for scripts and directories.

What is the difference between kill and kill -9?

kill sends SIGTERM, which lets the program clean up and exit. kill -9 sends SIGKILL, which ends it immediately with no cleanup; use it only when TERM fails.

Related cheat sheets