Essential Commands
These are the commands that form the backbone of daily work. Learn them until they’re muscle memory.
Navigation & filesystem
Section titled “Navigation & filesystem”# Where am I?pwd
# List files — human-readable sizes, show hiddenls -lah
# Move aroundcd /etc/nginxcd - # back to previous directorycd ~ # home directory
# Find filesfind /var/log -name "*.log" -mtime -1 # modified in last 24hfind . -type f -size +100M # files over 100 MB
# Search inside filesgrep -rn "ERROR" /var/log/app/grep -v "DEBUG" app.log # exclude DEBUG linesInspecting files
Section titled “Inspecting files”# Quick lookcat /etc/os-releasehead -20 /var/log/syslogtail -f /var/log/nginx/access.log # follow in real time
# Paged viewless /etc/nginx/nginx.conf # q to quit, / to search
# Word/line countwc -l access.logProcess management
Section titled “Process management”$ 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
# Kill a processkill -15 1234 # SIGTERM — graceful shutdownkill -9 1234 # SIGKILL — force kill (last resort)killall nginx
# Background jobslong-running-command & # run in backgroundjobs # list background jobsfg %1 # bring job 1 to foregroundNetworking
Section titled “Networking”# Socket / port inspectionss -tlnp # listening TCP sockets + processss -s # summary statistics
# Interface configurationip addr showip route show
# DNS lookupdig almamy.netdig +short almamy.net Anslookup almamy.net
# Connectivity testcurl -v https://almamy.netcurl -o /dev/null -s -w "%{http_code}" https://almamy.net
# Transfer filesscp user@host:/path/file .rsync -avz --progress ./local/ user@host:/remote/File permissions
Section titled “File permissions”# Read the permission string: drwxr-xr-x# d = directory | rwx = owner | r-x = group | r-x = others
chmod 755 script.sh # rwxr-xr-xchmod 600 ~/.ssh/id_rsa # rw------- (private key)chmod +x deploy.sh # add execute for all
chown www-data:www-data /var/www/htmlchown -R app:app /opt/app/
# Check effective permissionsstat -c "%a %n" /etc/shadow # octal + nameDisk & memory
Section titled “Disk & memory”# Disk usagedf -h # filesystem usagedu -sh /var/log/* # directory sizes
# Memoryfree -hvmstat 1 5 # 5 samples, 1 second apart
# I/Oiostat -x 1iotop # per-process I/OSystemd services
Section titled “Systemd services”# Statussystemctl status nginxsystemctl list-units --state=failed
# Controlsystemctl start nginxsystemctl stop nginxsystemctl restart nginxsystemctl reload nginx # reload config without restart
# Enable at bootsystemctl enable nginxsystemctl disable nginx
# Logsjournalctl -u nginx # all nginx logsjournalctl -u nginx -f # followjournalctl -u nginx --since "1 hour ago"journalctl -p err # only errorsText processing
Section titled “Text processing”# Column extractioncat /etc/passwd | cut -d: -f1 # usernames onlyawk '{print $1, $NF}' access.log # first and last columns
# Sort and uniquesort -rn counts.txt | head -10 # top 10 by countsort | uniq -c | sort -rn # frequency count pattern
# Stream editingsed 's/old/new/g' file.txtsed -i 's/localhost/0.0.0.0/g' config.ini # in-place edit
# JSONcat response.json | jq '.items[].name'curl -s api.example.com | jq '.[] | select(.status == "active")'Shortcuts worth knowing
Section titled “Shortcuts worth knowing”| Shortcut | Action |
|---|---|
Ctrl+C | Interrupt current process |
Ctrl+Z | Suspend to background |
Ctrl+R | Reverse search history |
Ctrl+L | Clear screen |
!! | Repeat last command |
!$ | Last argument of previous command |
Alt+. | Insert last argument (same as !$) |