Commands by lig0n (2)

  • Scrap everything and use `gawk` to do all the magic, since it's like the future or something. gawk 'match($11, /[a-z]{3}$/) && match($9, /^ata-/) { gsub("../", ""); print $11,"\t",$9 }' Yank out only ata- lines that have a drive letter (ignore lines with partitions). Then strip ../../ and print the output. Yay awk. Be sure to see the alternatives as my initial command is listed there. This one is a revision of the original. Show Sample Output

    ls -l /dev/disk/by-id |gawk 'match($11, /[a-z]{3}$/) && match($9, /^ata-/) { gsub("../", ""); print $11,"\t",$9 }' |sort
    lig0n · 2015-05-18 15:42:33 1
  • This is much easier to parse and do something else with (eg: automagically create ZFS vols) than anything else I've found. It also helps me keep track of which disks are which, for example, when I want to replace a disk, or image headers in different scenarios. Being able to match a disk to the kernels mapping of said drive the disks serial number is very helpful ls -l /dev/disk/by-id Normal `ls` command to list contents of /dev/disk/by-id grep -v "wwn-" Perform an inverse search - that is, only output non-matches to the pattern 'wwn-' egrep "[a-zA-Z]{3}$" A regex grep, looking for three letters and the end of a line (to filter out fluff) sed 's/\.\.\/\.\.\///' Utilize sed (stream editor) to remove all occurrences of "../../" sed -E 's/.*[0-9]{2}:[0-9]{2}\s//' Strip out all user and permission fluff. The -E option lets us use extended (modern) regex notation (larger control set) sed -E 's/->\ //' Strip out ascii arrows "-> " sort -k2 Sort the resulting information alphabetically, on column 2 (the disk letters) awk '{print $2,$1}' Swap the order of the columns so it's easier to read/utilize output from sed 's/\s/\t/' Replace the space between the two columns with a tab character, making the output more friendly For large ZFS pools, this made creating my vdevs immeasurably easy. By keeping track of which disks were in which slot (spreadsheet) via their serial numbers, I was able to then create my vols simply by copying and pasting the full output of the disk (not the letter) and pasting it into my command. Thereby allowing me to know exactly which disk, in which slot, was going into the vdev. Example command below. zpool create tank raidz2 -o ashift=12 ata-... ata-... ata-... ata-... ata-... ata-... Show Sample Output

    ls -l /dev/disk/by-id |grep -v "wwn-" |egrep "[a-zA-Z]{3}$" |sed 's/\.\.\/\.\.\///' |sed -E 's/.*[0-9]{2}:[0-9]{2}\s//' |sed -E 's/->\ //' |sort -k2 |awk '{print $2,$1}' |sed 's/\s/\t/'
    lig0n · 2015-01-25 19:29:40 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

Disable system bell in an X session
Execute this command in a terminal to disable the system-bell during X-session lifetime.

The command used by applications in OS X to determine whether a plist is "good". from Ed Marczak.
The check an entire folder is a one-liner: plutil -lint * | grep -v OK$ from Ed Marczak

Get version of loaded kernel module
Returns the version of the kernel module specified as "MODULENAME", when available.

Rename files in batch

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Inserts the results of an autocompletion in the command line
Pressing ESC then * will insert in the command line the results of the autocompletion. It's hard to explain but if you look the sample output or do $ echo ESC * you will understand quickly. By the way, few reminders about ESC : - Hold ESC does the same thing as tab tab - 'ESC .' inserts the last argument of last command (can be done many times in order to get the last argument of all previous commands)

Add a shadow to picture
Please take notice that if you are going to use an JPG file for shadow effect, let change -background none to -background white! Because -background none make a transparent effect while JPG doesn't support transparent! And when viewing, you will get a bacl box! So we will use an white background under! We can use other color as well!

Show memory stats on Nexenta/Solaris

Install pip with Proxy
Installs pip packages defining a proxy

Batch rename extension of all files in a folder, in the example from .txt to .md
Batch rename extension of all files in a folder, in the example from .txt to .md mmv most likely must be installed, but is very powerfull when you want to move/copy/append/link multiple files by wildcard patterns.

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: