← Back
πŸ–₯️ tmux β€” Terminal Multiplexer
1

Install & Start a Session

tmux lets you run multiple terminals inside one window and keep them alive after you disconnect.

bash β€” Install
sudo apt update && sudo apt install -y tmux
bash β€” Start a named session
# Start a new session called "work"
tmux new -s work
πŸ’‘
Inside tmux, every command starts with the prefix key Ctrl+b: press Ctrl+b, release, then press the command key (e.g. Ctrl+b then d to detach).
2

Detach & Reattach

Detach to leave a session running in the background β€” perfect for long jobs over SSH.

tmux keys β€” inside a session
Ctrl+b  d      # Detach (session keeps running after you disconnect SSH)
bash β€” From the shell
# List running sessions
tmux ls

# Reattach to the "work" session
tmux attach -t work

# Kill a session when you are done
tmux kill-session -t work
3

Windows & Panes

Windows are like tabs; panes split one window into multiple terminals. All keystrokes are pressed after the Ctrl+b prefix.

tmux keys β€” inside a session
# --- Windows (tabs) ---
Ctrl+b  c      # Create a new window
Ctrl+b  n      # Next window
Ctrl+b  p      # Previous window
Ctrl+b  0-9    # Jump to window by number

# --- Panes (splits) ---
Ctrl+b  %      # Split vertically (left | right)
Ctrl+b  "      # Split horizontally (top / bottom)
Ctrl+b  ←↑↓→   # Switch between panes with arrow keys
Ctrl+b  x      # Close the current pane (or just type: exit)
πŸ”„ rsync β€” Sync & Backup
4

Local Copy

The -a flag preserves permissions, timestamps and symlinks; -v is verbose.

bash
# Copy the CONTENTS of /src into /dest
rsync -av /src/ /dest/
⚠️
Trailing slash matters: /src/ copies the contents of src into dest, while /src (no slash) copies the directory itself into dest (creating /dest/src/).
5

Over SSH

Add -z to compress data in transit and -e ssh to use SSH as the transport.

bash β€” Push (local β†’ remote)
rsync -avz -e ssh /local/dir/ user@server:/remote/dir/
bash β€” Pull (remote β†’ local)
rsync -avz -e ssh user@server:/remote/dir/ /local/dir/
6

Mirror with --delete (Dry-Run First)

Always preview a mirror with --dry-run before running it for real.

bash β€” Preview only
# Show what WOULD change β€” nothing is written
rsync -av --delete --dry-run /src/ /dest/
bash β€” Run for real
# Same command without --dry-run, with a progress bar
rsync -av --delete --progress /src/ /dest/
bash β€” Exclude files
# Skip a directory
rsync -av --exclude='node_modules' /src/ /dest/

# Or read patterns from a file (one per line)
rsync -av --exclude-from=excludes.txt /src/ /dest/
⚠️
--delete is destructive: it removes any files in the destination that no longer exist in the source. Dest becomes an exact mirror of source β€” run the dry-run first every time.
⏰ cron β€” Scheduling
7

Edit the Crontab

Each user has their own crontab. Use crontab -e to edit it safely.

bash
# Edit your own crontab
crontab -e

# List your current cron jobs
crontab -l

# Edit another user's crontab (needs root)
sudo crontab -e -u username
8

Cron Syntax & Examples

Five time fields, then the command to run.

crontab β€” Field layout
# β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€ minute        (0-59)
# β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€ hour          (0-23)
# β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€ day of month  (1-31)
# β”‚ β”‚ β”‚ β”Œβ”€β”€β”€ month         (1-12)
# β”‚ β”‚ β”‚ β”‚ β”Œβ”€ day of week    (0-7, Sun=0 or 7)
# β”‚ β”‚ β”‚ β”‚ β”‚
# * * * * *  command-to-run
crontab β€” Examples
0 3 * * *      /path/script.sh   # Every day at 3:00 AM
*/15 * * * *   /path/script.sh   # Every 15 minutes
0 9 * * 1-5    /path/script.sh   # 9:00 AM, Mon–Fri
@reboot        /path/script.sh   # Once at every boot
@daily         /path/script.sh   # Once a day (midnight)
crontab β€” Log the output
# Redirect stdout AND stderr to a log file
0 3 * * * /path/script.sh >> /var/log/myjob.log 2>&1
9

System-Wide Cron & Logs

Beyond per-user crontabs, the system has drop-in locations and run-part directories.

bash β€” System cron locations
# Drop custom job files here (note the extra "user" field)
/etc/cron.d/

# The main system crontab
/etc/crontab

# Scripts placed here run automatically:
/etc/cron.daily/    # run once a day
/etc/cron.weekly/   # run once a week
/etc/cron.monthly/  # run once a month
bash β€” Check that jobs actually ran
# View cron activity via the journal
journalctl -u cron

# Or grep the syslog (older systems)
grep CRON /var/log/syslog
πŸ’‘
cron runs with a minimal PATH (usually just /usr/bin:/bin), so it won't find commands the way your login shell does. Use absolute paths in your scripts and cron lines, or set PATH= at the top of the crontab.