> Use sed to Insert Text Every 'n' Lines/Characters

There are a lot of overly complicated ways to insert a line after every nth line, but the simplest way I find is the following: sed '0~3 s/$/\nMy Text/g' < input.file In a file with six lines you get something like the following: Line 1 Line…

> Check out a _link from OBS

If you're looking to edit the _link file stored in the repository underlying your OBS you can check it out with the --unexpand-link option. Otherwise you'll end up with the _service file: osc checkout --unexpand-link <Project> <Package> # or if you're already in the project's directory: osc…

> Always Display Filename with grep

The easiest way to accomplish this is if you have a relatively recent GNU version of grep. Then the -H version is available to you: printf "This\nis\a\ntest" > /tmp/grep.test grep -H 'is' /tmp/grep.test /tmp/grep.test:This /tmp/grep.test:is But if…

> Add/Remove Passphrase from Existing Private Key

If you've got a private key you're fond of that either has or lacks a passphrase(password) and you'd like to add (because you'd like to put it someplace you trust slightly less) or remove (because you're moving it someplace you trust more [really?]) it's really straight forward. To add…

> Best Way to Copy Dotfiles

I've seen a lot of convoluted solutions floating around regarding how to copy files starting with .. The problem everyone is trying to avoid is that when you run something like: cp -r A/.* B/ The above command starts copying everything the entire "A" directory (.) and then from the parent directory…

> Become an SSH Ninja: SSH Tips and Tricks

OpenSSH has some pretty cool tricks up its sleeve beyond it's "Clark Kent"-esque ability to provide a secure command line interface on a remote system. Here are some of its more "Superman"-type abilities: Public-Key Authentication Learn to Love Your .ssh/config Agent Forwarding Sharing Connections Bonus Use Tab-Completion…

> Redirect Output of an Already Running Process

Have you ever started a long running command and then wanted to put it in the background but it's sending its output to STDOUT? Here's a script that uses gdb to swap a processes file descriptors so you can send all that output to a file, or /dev/null after…

> Use Redirection Instead of Temp Files

There are certain commands that really want to read input in from a file, like diff. However, if what you're trying to manipulate or use with one of these commands is actually output from another command usually you'd have to write this information out to a file before reading it…

> Adding a Little Color to Recursive diffs

I have routine need to recursively diff two large directory trees with small changes sprinkled throughout. After staring at pages and pages of one diffed file after another it becomes easy to lose track of what two files' differences I'm looking at. An easy way to keep track of things…

> Simple CLI Based Timer Alias

Here's a quick alias that will start up a timer and report the total time after a control-C. alias timer='which banner>/dev/null 2>&1;[ $? -eq 0 ]&&c=banner||c=echo;export ts=$(date +%s);p='\''$(date -u -d @"$(($(date +%s)-$…