Commands by scw (3)

What's this?

commandlinefu.com 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

Formatted list - WWNs of all LUNs
Use `scsi_id` to positively identify which LUNs are which (i.e. compare with the list of LUNs you created on your disk array) (shown: RHEL5 usage) Debian usage: $ # for i in /dev/sd* ; do wwn=`/lib/udev/scsi_id -g --device $i` ; [ "$wwn" != "" ] && echo -e ${i##*/}'\t'$wwn ;done

graphical memory usage
smem is very clever, it keeps in mind shared memory in its calculations!!! http://www.selenic.com/smem/

Rename files in batch

Rapidly invoke an editor to write a long, complex, or tricky command
Allows you to edit your command using your chosen editor. Works in bash with "set -o vi".

Find all the files more than 10MB, sort in descending order of size and record the output of filenames and size in a text file.
This command specifies the size in Kilobytes using 'k' in the -size +(N)k option. The plus sign says greater than. -exec [cmd] {} \; invokes ls -l command on each file and awk strips off the values of the 5th (size) and the 9th (filename) column from the ls -l output to display. Sort is done in reversed order (descending) numerically using sort -rn options. A cron job could be run to execute a script like this and alert the users if a dir has files exceeding certain size, and provide file details as well.

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" }

Copy files to a remote host with SFTP with a leading dot, then rename them to the real file name
Usage: $ sftp-cp * | sftp user@host:/dir This is useful if there is a process on the remote machine waiting for files in an incoming directory. This way it won't see half-transmitted files if it ignores hidden files.

Multiple variable assignments from command output in BASH
This version uses read instead of eval.

True Random Dice Roll
/dev/urandom is cryptographically secure, and indistinguishable from true random, as it gathers data from external sources, influenced by human timing interactions with computers, to fill the entropy pool, and hashes the input with SHA-1. As such, this is a quick way to do a "true random" fair-6 dice roll. Using this method, you could easily create passphrases with Diceware http://diceware.com. Change the head(1) count to something other than 5 for more or less numbers.

Search commandlinefu.com from the command line using the API
Search for one/many words on commandlinefu, results in vim for easy copy, manipulation. The -R flag is for readonly mode...you can still write to a file, but vim won't prompt for save on quit. What I'd really like is a way to do this from within vim in a new tab. Something like $ :Tex path/to/file but $ :cmdfu search terms


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: