What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. 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.

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!

Top Tags



Commands using bc from sorted by
Terminal - Commands using bc - 40 results
b(){ echo "scale=${2:-2}; $1" | bc -l; }
2009-12-23 23:44:31
User: dadi
Functions: bc echo

terms inclosing '()' must be enclosed by "" (soft quotes)

bash variables must be referenced: b $x/$y

ugly bracket checking (balanced, fractions...)

default precision 2

mplayer -vo dummy -ao dummy -identify * 2>&1 | grep ID_LENGTH | sed 's/.*=\([0-9]*\)/\1/' | xargs echo | sed 's/ /+/g' | bc | awk 'S=$1; {printf "%dh:%dm:%ds\n",S/(60*60),S%(60*60)/60,S%60}'
2009-09-24 10:33:19
User: Strawp
Functions: awk bc echo grep sed xargs

You're behind on your TV catch-up, but how far behind? This command tries to open mplayer against all files in the current dir. If it's a video file it will contain ID_LENGTH, which is summed and output in hours, minutes and seconds.

Someone better at awk could probably reduce this down a lot.

bc -l <<< "x=2; p=0.5; e(l(x)*p)"
bc -l <<< s(3/5)
2009-09-02 15:41:39
User: akg240
Functions: bc

-l auto-selects many more digits (but you can round/truncate in your head, right) plus it loads a few math functions like sin().

tempo=33; slope=10; maxfreq=888; function sinus { echo "s($1/$slope)*$maxfreq"|bc -l|tr -d '-'; }; for((i=1;;i++)); do beep -l$tempo -f`sinus $i`; done
2009-07-10 21:24:11
User: 5z474n
Functions: bc echo tr

Infinitely plays beeps with sinusoidally changing sound frequency. Ideal for alarm on an event.

? () { echo "$*" | bc -l; }
2009-06-28 20:15:30
User: fizz
Functions: bc echo

defines a handy function for quick calculations from cli.

once defined:

? 10*2+3
watch --no-title -d -n 1 'echo `date -d "next Thursday" +%s` "-" `date +%s` | bc -l'
2009-03-29 06:53:09
User: jnash
Functions: bc watch

Might be more useful if you were able to print it in Days HH:MM:SS format as:

perl -e [email protected]=gmtime(234234);printf("%d Days %02d:%02d:%02ds\n",@p[7,2,1,0]);'

But I'm not exactly sure how to replace the 234234 with the output of the countdown time. (Having some problems with nested quoting/command substitution). Help would be appreciated :)

echo "obase=2; 27" | bc -l
2009-03-25 09:54:50
User: polar
Functions: bc echo
Tags: bc

Easily convert numbers to their representations in different bases. Passing

"ibase=16; obase=8; F2A"

to bc will convert F2A (3882 in decimal) from Hex to Octal, and so on.

echo "$math_expr" | bc -l
2009-03-25 09:46:01
User: polar
Functions: bc echo
Tags: bc

Useful for quick calculations at the command line. $math_expr is any arithmetic expression (see sample output):



More options in the bc man page.

2009-03-24 16:19:12
User: haivu
Functions: bc

bc is a wonderful calculator. Just type bc at the command line and have at it. Ctrl+D (or type quit) will get you out. This usage is just scratching the surface: bc can handle a mini scripting language, complete with variable, statements, loop, conditional statements and more. Do a man page on it to find out.

echo '123/7' |bc -l |xargs printf "%.3f\n"
for i in $(seq 0 5) ; do echo "5 - $i" | bc -l ; sleep 60 ; done && echo "bye, bye" && shutdown -h now
2009-03-13 12:16:35
User: arctarus
Functions: bc echo seq shutdown sleep

command to turn off your computer when you go home and can not wait

echo -en "stats\r\n" "quit\r\n" | nc localhost 11211 | tr -s [:cntrl:] " "| cut -f42,48 -d" " | sed "s/\([0-9]*\)\s\([0-9]*\)/ \2\/\1*100/" | bc -l
echo "8000000/(20*6*86400)" | bc -l
echo '2^2^20' | time bc > /dev/null
2009-02-06 02:31:55
User: mkc
Functions: bc echo time

This is a quick and dirty way to generate a (non-floating-point) CPU-bound task to benchmark. Adjust "20" to higher or lower values, as needed. As a benchmark this is probably a little less bogus than bogomips, and it will run anywhere 'bc' does.