mtnr

A tech blog with fries on the side

  • 5 Terminal Tricks That Will Save You Time Every Day

    Whether you’re on macOS or Linux, your shell is hiding some surprisingly powerful shortcuts. Here are five tricks — spanning both zsh and bash — that are easy to learn and genuinely useful.


    1. !$ and $_ — Reuse the Last Argument

    How often do you run a command and immediately need to use the same argument again?

    mkdir -p /some/deeply/nested/directory
    cd !$
    

    !$ expands to the last argument of the previous command, so you don’t have to type that long path twice. In interactive shells you can also use $_, which does the same thing but works more reliably inside scripts.

    Note: !$ is a history expansion — it’s evaluated before the command runs and will be visible if you press Tabto expand it first. $_ is a special shell variable set after each command completes.


    2. ^old^new — Quick Command Substitution

    Made a typo in the last command? Instead of pressing  and hunting for the mistake, use caret substitution:

    git comit -m "fix typo"
    ^comit^commit
    # Runs: git commit -m "fix typo"
    

    This replaces the first occurrence of old with new in the previous command and re-runs it. It’s a bash and zsh history expansion, so it works in both.


    3. cd - — Jump Back to the Previous Directory

    cd - switches you to whichever directory you were in before the current one. It’s like a back button for your filesystem.

    cd /var/log
    cd /etc/nginx
    cd -         # Back to /var/log
    cd -         # Back to /etc/nginx
    

    zsh takes this a step further with a built-in directory stack. Running cd - followed by Tab in zsh gives you a numbered list of recent directories to jump to directly — handy when you’re hopping between more than two locations.


    4. pbcopy / pbpaste (macOS) and xclip / xsel (Linux)

    These commands pipe data into and out of your system clipboard, which is incredibly useful for moving output between the terminal and other apps.

    macOS:

    cat ~/.ssh/id_ed25519.pub | pbcopy   # Copy your public key to clipboard
    pbpaste > notes.txt                  # Paste clipboard content into a file
    

    Linux (install xclip first):

    cat ~/.ssh/id_ed25519.pub | xclip -selection clipboard
    xclip -selection clipboard -o > notes.txt
    

    A convenient alias to make Linux feel like macOS:

    alias pbcopy='xclip -selection clipboard'
    alias pbpaste='xclip -selection clipboard -o'
    

    5. Background Jobs — Don’t Let Long Tasks Hold Your Terminal Hostage

    Running a long process? You don’t have to open a new terminal tab. The shell has built-in job control for exactly this.

    Send a running process to the background:

    1. Press Ctrl+Z to suspend it.
    2. Run bg to resume it in the background.

    Start a process directly in the background:

    npm run build &
    

    Manage your jobs:

    jobs          # List all background jobs
    fg            # Bring the most recent job back to the foreground
    fg %2         # Bring job number 2 to the foreground
    

    Heads up: A backgrounded job is still tied to your terminal session. If you close it, the process gets killed. To truly detach a process so it survives after you log out, use nohup:

    nohup ./my-script.sh &
    

    Or reach for tmux or screen for a more complete session management experience.


    These shortcuts take only minutes to learn but add up to real time savings over a day of terminal work. Try adding the pbcopy/pbpaste aliases to your .zshrc or .bashrc today — your future self will thank you.

  • Yet another how to run WordPress with Docker tutorial

    There are already a lot of tutorials on how to run a WordPress blog from a Docker image. This one is more of the same and yet a little different. The usual approach includes a full stack containing WordPress as well as a database (e.g., MySQL, MariaDB, Postgres, etc.). However, since I was planning on…

  • Roll Your Own Network

    One stop shop for rolling your own network. You’ll find tutorials on how to run a network, server, desktop, mobile, and manage certificates and backups. It’s a work in progress according to themselves, but definitely worthwhile checking it out! https://roll.urown.net

  • Better backups with BorgBase

    I recently posted an article on how I used rsnapshot for backing up this blog. This worked fine but I was having two major issues with the approach. 1. Backing up the database’s internal file storage Generally speaking, it’s bad practice to backup a database’s internal file storage as it could change mid-backup. A better…

  • Get your backups to safety with rsnapshot

    In this article we learned how to backup Docker volumes. However, storing them on the same machine won’t do us any good should, for example, the harddrive fail. rsnapshot to the rescue. I run rsnsapshot as a Docker container from my home server and have set up a ssh source in the rsnapshot config file…