Commands by dfear (1)

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

Test load balancers
With the "--resolve" switch, you can avoid doing DNS lookups or edit the /etc/hosts file, by providing the IP address for a domain directly. Useful if you have many servers with different IP addresses behind a load balancer. Of course, you would loop it: $ for IP in 10.11.0.{1..10}; do curl --resolve$IP -I -s; done

STAT Function showing ALL info, stat options, and descriptions
This shows every bit of information that stat can get for any file, dir, fifo, etc. It's great because it also shows the format and explains it for each format option. If you just want stat help, create this handy alias 'stath' to display all format options with explanations. $ alias stath="stat --h|sed '/Th/,/NO/!d;/%/!d'" To display on 2 lines: $ ( F=/etc/screenrc N=c IFS=$'\n'; for L in $(sed 's/%Z./%Z\n/'

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

Binary clock
Fun idea! This one adds seconds and keeps running on the same line. Perl's probably cheating though. :)

Poor man's unsort (randomize lines)

Define a quick calculator function
defines a handy function for quick calculations from cli. once defined: $ ? 10*2+3

function to compute what percentage of X is Y? Where percent/100 = X/Y => percent=100*X/Y
This function make it easy to compute X/Y as a percentage. The name "wpoxiy" is an acronym of "what percentage of X is Y"

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

rotate the compiz cube via command line
0-1279 = desktop 1 region = face 1 1280-2559 = face 2 ==>> wmctrl 1280 = wmctrl (1281,...2559) are all the same for a 1280 monitor resolution math: argument of wmctrl -o = ( DesiredFace * HorizontalResolution - 1)

create ICO file with more than one image
requires imagemagick. -background transparent is of course optional.

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: