Advanced Terminal Techniques

Elevate your command line expertise with professional-grade tools, automation strategies, and system-level mastery

Shell Scripting

#!/bin/bash

Shebang for bash scripts

#!/bin/bash
# Simple backup script
tar -czf backup-$(date +%F).tar.gz /data

💡 Use set -euo pipefail for safer scripts

trap

Handle signals and cleanup

trap 'rm -f tempfile' EXIT

source

Load functions/variables

source ~/.bashrc

echo

Display a line of text

echo 'Hello, World!'

Process Mastery

bg/fg

Background/foreground processes

firefox & # Start in background
fg %1 # Bring to foreground

disown

Detach process from shell

long_running.sh &
disown

nohup

Run commands immune to hangups

nohup ./server.sh > output.log &

pstree

Display a tree of processes

pstree

Networking Pro

nc

Netcat swiss army knife

nc -zv example.com 80 # Port scan

💡 Combine with pipes for network testing

sshuttle

VPN over SSH

sshuttle -r user@server 0/0

mtr

Network diagnostic tool

mtr -rw example.com

wget

Download files from the web

wget https://example.com/file.zip

System Wizardry

strace

Trace system calls

strace -f -e trace=file ls

ldd

List shared lib dependencies

ldd /usr/bin/bash

gdb

GNU Debugger

gdb -p $(pidof process)

htop

Interactive process viewer

htop

Power User Toolbox

ZSH Power

Enhance your shell with ZSH features:

â–¸zplug - Plugin manager
â–¸zstyle - Completion styling
â–¸zmv - Advanced mass renaming
zmv '(*).txt' '${1}.md'

CLI Fu

Advanced command combinations:

â–¸!ssh:0 - Last ssh command
â–¸Alt+. - Insert last argument
â–¸Ctrl+X Ctrl+E - Edit in $EDITOR

Terminal Multiplexing

Master tmux workflows:

â–¸tmux new -s session
â–¸Ctrl+b d - Detach session
â–¸tmuxp - Session manager

Handle With Care!

rm -rf /

Recursive force delete root

Prevention: alias rm='rm -i'

dd if=/dev/random

Disk destruction

Prevention: Triple-check input/output files

:(){ :|:& };:

Fork bomb

Prevention: ulimit -u to limit processes

chmod -R 777 /

Permission chaos

Prevention: Use 755 for dirs, 644 for files