Linux Handy Commands

A quick English cheat sheet for everyday Linux work (safe, practical, copy-paste friendly).

Quick Safety Note read me

Be careful with commands that write or delete files (rm, dd, mv, chown, etc.). When in doubt, run the “read-only” version first (like ls or cat), or add --dry-run if supported.

Navigation & Files

Where am I / what's here?

pwd
ls -lah

Search files and text

# find files by name (case-insensitive)
find . -iname "*nginx*"

# search text inside files (recursive)
grep -RIn "server_name" /etc/nginx

View files

cat file.txt
less -S /var/log/nginx/error.log

Disk usage

df -h
du -sh *
du -sh /var/log/* | sort -h

Processes & Performance

See what's running

ps aux | less
pgrep -a nginx

Top-like monitors

top
htop   # if installed

Kill a process (careful)

kill -TERM <PID>
kill -KILL <PID>   # last resort

Memory & CPU info

free -h
lscpu

Networking

IP and routes

ip a
ip r

Check listening ports

ss -tulpn
ss -tulpn | grep -E ":80|:443"

DNS and connectivity

dig example.com +short
ping -c 4 8.8.8.8
curl -I https://example.com

Download

curl -L -o file.zip https://example.com/file.zip
wget -O file.zip https://example.com/file.zip

Logs & Troubleshooting

Follow logs in real time

tail -f /var/log/syslog
tail -f /var/log/messages

systemd journal

# follow logs for a service
journalctl -u nginx -f

# show recent logs
journalctl -u nginx --since "1 hour ago"

Nginx quick checks

nginx -t
nginx -T | less

Permissions

Who owns it / what are permissions?

ls -l
stat file.txt

Change permissions (careful)

chmod 644 file.txt
chmod -R u+rwX,go-rwx private_dir

Change ownership (careful)

sudo chown user:group file.txt
sudo chown -R user:group /var/www/html

Archive & Compression

tar

# create
tar -czf backup.tar.gz folder/

# extract
tar -xzf backup.tar.gz

zip

zip -r archive.zip folder/
unzip archive.zip

Package Management (common)

Debian/Ubuntu

sudo apt update
sudo apt install <package>

RHEL / AlmaLinux / Rocky

sudo dnf update
sudo dnf install <package>

Tip: if a command is missing, search the package name with apt-cache search or dnf search.

Bonus: Useful One-Liners

# show the 20 largest files under current directory
find . -type f -printf "%s\t%p\n" 2>/dev/null | sort -n | tail -n 20

# show recent modified files (last 24h)
find . -type f -mtime -1 -ls 2>/dev/null | head

# quickly see your public IP
curl -s https://ifconfig.me; echo

Note: The public IP command depends on an external website.