Commands by jharr (1)

  • Clone a root partition. The reason for double-mounting the root device is to avoid any filesystem overlay issues. This is particularly important for /dev. Also, note the importance of the trailing slashes on the paths when using rsync (search the man page for "slash" for more details). rsync and bash add several subtle nuances to path handling; using trailing slashes will effectively mean "clone this directory", even when run multiple times. For example: run once to get an initial copy, and then run again in single user mode just before rebooting into the new disk. Using file globs (which miss dot-files) or leaving off the trailing slash with rsync (which will create /mnt/target/root) are traps that are easy to fall into.

    mount /dev/root /mnt/root; rsync -avHX /mnt/root/ /mnt/target/
    jharr · 2011-08-24 14:29:17 0

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Check These Out

Video Google download
Download google video with wget. Or, if you wish, pass video URL to ie mplayer to view as stream. 1. VURL: replace with url. I.e. 2. OUPUT_FILE : optionally change to a more suited name. This is the downloaded file. I.e. foo.flv # Improvements greatly appreciated. (close to my first linux command after ls -A :) ) Breakedown pipe by pipe: 1. wget: html from google, pass to stdout 2. grep: get the video url until thumbnailUrl (not needed) 3. grep: Strip off everything before http:// 4. sed: urldecode 5. echo: hex escapes 6. sed: stipr of tailing before thumbnailUrl 7. wget: download. Here one could use i.e. mplayer or other...

Get the full path of a bash script's Git repository head.
Rather than complicated and fragile paths relative to a script like "../../other", this command will retrieve the full path of the file's repository head. Safe with spaces in directory names. Works within a symlinked directory. Broken down: $cd "$(dirname "${BASH_SOURCE[0]}")" temporarily changes directories within this expansion. Double quoted "$(dirname" and ")" with unquoted ${BASH_SOURCE[0]} allows spaces in the path. $git rev-parse --show-toplevel gets the full path of the repository head of the current working directory, which was temporarily changed by the "cd".

Exit mc with 2 keystrokes
For those who like to hit instead of typing "exit" to leave the shell and find it annoying that it doesn't work in Midnight Commander, just press to switch to the subshell and now you can leave with

Find usb device in realtime
Using this command you can track a moment when usb device was attached.

list block devices
Shows all block devices in a tree with descruptions of what they are.

List only the directories
to include hidden dirs use: $ tree -adL 1 (with ls, requires 'ls -ad */ .*/')

cat stdout of multiple commands
Concatenate the stdout of multiple commands.

floating point operations in shell scripts
using bc is for sissies. dc is much better :-D Polish notation will rule the world...

Create patch file for two directories

# first install arp-scan if not have it arp-scan .... show ip+mac in localnet awk '/00:1b:11:dc:a9:65/ {print $1}' .... get ip associated with MAC ` backtick make do command substitution passing ip to command ping

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: