Skip to content

Essential Commands

These are the commands that form the backbone of daily work. Learn them until they’re muscle memory.

Terminal window
# Where am I?
pwd
# List files — human-readable sizes, show hidden
ls -lah
# Move around
cd /etc/nginx
cd - # back to previous directory
cd ~ # home directory
# Find files
find /var/log -name "*.log" -mtime -1 # modified in last 24h
find . -type f -size +100M # files over 100 MB
# Search inside files
grep -rn "ERROR" /var/log/app/
grep -v "DEBUG" app.log # exclude DEBUG lines
Terminal window
# Quick look
cat /etc/os-release
head -20 /var/log/syslog
tail -f /var/log/nginx/access.log # follow in real time
# Paged view
less /etc/nginx/nginx.conf # q to quit, / to search
# Word/line count
wc -l access.log
Inspect running processes

$ ps aux | grep nginx root 1234 0.0 0.1 10824 3456 ? Ss 09:00 0:00 nginx: master www-data 1235 0.0 0.0 11280 2048 ? S 09:00 0:00 nginx: worker

$ # Show process tree $ pstree -p 1234

$ # Interactive monitor $ htop

Terminal window
# Kill a process
kill -15 1234 # SIGTERM — graceful shutdown
kill -9 1234 # SIGKILL — force kill (last resort)
killall nginx
# Background jobs
long-running-command & # run in background
jobs # list background jobs
fg %1 # bring job 1 to foreground
Terminal window
# Socket / port inspection
ss -tlnp # listening TCP sockets + process
ss -s # summary statistics
# Interface configuration
ip addr show
ip route show
# DNS lookup
dig almamy.net
dig +short almamy.net A
nslookup almamy.net
# Connectivity test
curl -v https://almamy.net
curl -o /dev/null -s -w "%{http_code}" https://almamy.net
# Transfer files
scp user@host:/path/file .
rsync -avz --progress ./local/ user@host:/remote/
Terminal window
# Read the permission string: drwxr-xr-x
# d = directory | rwx = owner | r-x = group | r-x = others
chmod 755 script.sh # rwxr-xr-x
chmod 600 ~/.ssh/id_rsa # rw------- (private key)
chmod +x deploy.sh # add execute for all
chown www-data:www-data /var/www/html
chown -R app:app /opt/app/
# Check effective permissions
stat -c "%a %n" /etc/shadow # octal + name
Terminal window
# Disk usage
df -h # filesystem usage
du -sh /var/log/* # directory sizes
# Memory
free -h
vmstat 1 5 # 5 samples, 1 second apart
# I/O
iostat -x 1
iotop # per-process I/O
Terminal window
# Status
systemctl status nginx
systemctl list-units --state=failed
# Control
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx # reload config without restart
# Enable at boot
systemctl enable nginx
systemctl disable nginx
# Logs
journalctl -u nginx # all nginx logs
journalctl -u nginx -f # follow
journalctl -u nginx --since "1 hour ago"
journalctl -p err # only errors
Terminal window
# Column extraction
cat /etc/passwd | cut -d: -f1 # usernames only
awk '{print $1, $NF}' access.log # first and last columns
# Sort and unique
sort -rn counts.txt | head -10 # top 10 by count
sort | uniq -c | sort -rn # frequency count pattern
# Stream editing
sed 's/old/new/g' file.txt
sed -i 's/localhost/0.0.0.0/g' config.ini # in-place edit
# JSON
cat response.json | jq '.items[].name'
curl -s api.example.com | jq '.[] | select(.status == "active")'
ShortcutAction
Ctrl+CInterrupt current process
Ctrl+ZSuspend to background
Ctrl+RReverse search history
Ctrl+LClear screen
!!Repeat last command
!$Last argument of previous command
Alt+.Insert last argument (same as !$)