Commands by bigstupid (3)

  • This find syntax seems a little easier to remember for me when I have to use -prune on AIX's find. It works with gnu find, too. Add whatever other find options after -prune Show Sample Output

    find /some/directory/* -prune -type f -name *.log
    bigstupid · 2014-05-02 00:14:32 1
  • Shows a tree of the disks. Requires "tree" Show Sample Output

    tree /dev/disk
    bigstupid · 2014-04-20 18:56:56 0
  • For a given filesystem return the LUN ID. Command assumes 1:1 relationship between fs:lv:hdisk:lun which may not be the case in all environments. Show Sample Output

    getlunid() { lv=$(df -P $1|grep "^/dev/"|awk '{print $1}'|awk -F/ '{print $3}'); hd=$(lslv -l $lv|tail -1|awk '{print $1}');id=$(odmget -q "name like $hd AND attribute=unique_id" CuAt|grep "value ="|awk -F= '{print $2}'|tr -d '"');echo $id;}
    bigstupid · 2014-04-20 18:43:21 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

Verify if user account exists in Linux / Unix

a function to find the fastest free DNS server
Evoke from the command like as: $ timeDNS . This isn't too terribly practical, but it is a good code example of using subshells to run the queries in parallel and the use of an "anonymous function" (a/k/a "inline group") to group i/o. . I'm assuming you have already defined your local DNS cache as ${local_DNS}, (here, it's . You do need to install `moreutils` to get `sponge`. . If you're willing to wait, a slower version w/o sponge, (and w/o sorting), is this: . DNS () { for x in "" "" "" "" "" "" "" "" ""; do (echo -n "$x "; dig @"$x" "$*"|grep Query) ; done ; }

Copy files and directories from a remote machine to the local machine
This command will copy files and directories from a remote machine to the local one. Ensure you are in the local directory you want to populate with the remote files before running the command. To copy a directory and it's contents, you could: $ ssh user@host "(cd /path/to/a/directory ; tar cvf - ./targetdir)" | tar xvf - This is especially useful on *nix'es that don't have 'scp' installed by default.

continuously print string as if being entered from the keyboard
Cycles continuously through a string printing each character with a random delay less than 1 second. First parameter is min, 2nd is max. Example: 1 3 means sleep random .1 to .3. Experiment with different values. The 3rd parameter is the string. The sleep will help with battery life/power consumption. $ cycle 1 3 $(openssl rand 100 | xxd -p) Fans of "The Shining" might get a kick out of this: $ cycle 1 4 ' All work and no play makes Jack a dull boy.'

Burn CD/DVD from an iso, eject disc when finished.
cdrecord -scanbus will tell you the (x,y,z) value of your cdr (for example, mine is 3,0,0)

Creates Solaris alternate boot environment on another zpool.
PS: 'lustatus' gives the list of all alternate boot environments.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

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

Add a progress counter to loop (see sample output)
For this hack you need following function: $ finit() { count=$#; current=1; for i in "$@" ; do echo $current $count; echo $i; current=$((current + 1)); done; } and alias: $ alias fnext='read cur total && echo -n "[$cur/$total] " && read' Inspired by CMake progress counters.

ls not pattern
I've been looking for a way to do this for a while, get a not pattern for shell globs. This works, I'm using to grab logs from a remote server via scp.

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: