### Commands using bc (51) the last day the last week the last month all time sorted by date votes

• 0
echo \$(echo \$(seq \$MIN \$MAX) | sed 's/ /+/g') | bc -l
· 2010-01-29 16:41:07
• If you want a sequence that can be plotted, do: seq 8 | awk '{print "e(" \$0 ")" }' | bc -l | awk '{print NR " " \$0}' Other bc functions include s (sine), c (cosine), l (log) and j (bessel). See the man page for details. Show Sample Output

0
seq 8 | awk '{print "e(" \$0 ")" }' | bc -l
· 2010-08-14 02:52:39
• Use bc for decimals...

0
echo \$(echo 'scale=2; ' '100 * ' \$(eix --only-names -I | wc -l) / \$(eix --only-names | wc -l) | bc -l)%
· 2010-10-25 15:42:15
• Calculate pi from the infinite series 4/1 - 4/3 + 4/5 - 4/7 + ... This expansion was formulated by Gottfried Leibniz: http://en.wikipedia.org/wiki/Leibniz_formula_for_pi I helped rubenmoran create the sum of a sequence of numbers and he replied with a command for the sequence: 1 + 2 -3 + 4 ... This set me thinking. Transcendental numbers! seq provides the odd numbers 1, 3, 5 sed turns them into 4/1 4/3 4/5 paste inserts - and + bc -l does the calculation Note: 100 million iterations takes quite a while. 1 billion and I run out of memory. Show Sample Output

0
seq 1 2 99999999 | sed 's!^!4/!' | paste -sd-+ | bc -l
· 2011-02-09 23:36:07

• 0
for c in gcc bison dialog bc asdf; do if ! which \$c >/dev/null; then echo Required program \$c is missing ; exit 1; fi; done
· 2011-06-27 12:54:02
• I simply find binary notation more straightforward to use than octal in this case. Obviously it is overkill if you just 600 or 700 all of your files... Show Sample Output

0
function right { bc <<< "obase=8;ibase=2;\$1"; }; touch foo; chmod \$(right 111111011) foo; ls -l foo
· 2011-11-16 22:43:31

• 0
hexdec() { bc <<< "obase=10; ibase=16; \$1"; }
· 2011-12-22 04:40:54
• This was done in csh. Show Sample Output

0
echo `disklabel mfid1s4 | sed -n '\$p' | awk '{print \$2}'` / 1024 / 1024 | bc -l
· 2012-05-04 12:48:58
• Like in bash.

0
bc <<<"..."
· 2013-09-04 14:14:49
• I did not come up with this one myself, but found this somewhere else several months ago. Show Sample Output

0
openssl rand -hex 1 | tr '[:lower:]' '[:upper:]' | xargs echo "obase=2;ibase=16;" | bc | cut -c1-6 | sed 's/\$/00/' | xargs echo "obase=16;ibase=2;" | bc | sed "s/\$/:\$(openssl rand -hex 5 | sed 's/\(..\)/\1:/g; s/.\$//' | tr '[:lower:]' '[:upper:]')/"
· 2013-10-22 08:40:46
• Converts from base 10 to base 16

0
"ibase=10;obase=16;\$1" | bc -l
· 2014-06-02 14:40:56
• Change the scale to adjust number of decimal places prefix the command with "time" to benchmark the computer (compare how long it takes to calculate 10000 digits of pi on various computers). Show Sample Output

0
echo "scale=1000; 4*a(1)" | bc -l
· 2014-07-31 19:13:26
• The given file may contain any kind of characters. This is compatible for most simple mathematical operation. For the first number found, it will be replaced by the result of a factor operation of 1000. To change the filename or multiplactor or number regular expression, change the first fixed values. Show Sample Output

0
n=1000;f="test.csv";r='([0-9]+.{0,1}[0-9]*)';echo -n "" > new_\${f};cat \$f | while read l;do val=`echo \$l | egrep -o \$r` ; if [ ! -z \$val ];then newval=`echo \$val \* \$n | bc -l`;l=`echo \$l | sed "s/\$val/\$newval/"`;fi;echo \$l >> new_\${f};unset val;done
· 2017-04-26 18:04:07
• see summary. if you want to set dpi right away try this: xrandr --query | sed -n 's@\([A-Z0-1-]*\).* \(.*\)x\(.*\)+.*+.* \([0-9]\+\)mm x \([0-9]\+\)mm@"--output \1 --dpi ";(\2/\4+\3/\5)*12.7@p;'|bc -l|xargs -L1 xrandr all syntax should be POSIX compliant. Show Sample Output

0
xrandr --query | sed -n 's@\([A-Z0-1-]*\).* \(.*\)x\(.*\)+.*+.* \([0-9]\+\)mm x \([0-9]\+\)mm@"\1: ";(\2/\4+\3/\5)*12.7@p;'|bc -l
· 2017-06-23 03:44:40

• 0
obase=16; echo "\$(date +%s)" | bc | xxd -r -p | base32
· 2017-06-26 16:58:38

• 0
echo "\$(find ./ -name '*' -type f -exec wc -l {} \; | awk '{print \$1}' | tr '\n' '+' | sed s/+\$//g)" | bc -l
· 2018-10-26 09:20:50
• This shell calculator uses POSIX features only and is therefore portable. By default the number of significant figures is limited to 8 with trailing zeros stripped, resembling the display of a basic pocket calculator. You might want to increase this to 12 to emulate a scientific calculator. Show Sample Output

0
calc(){ printf "%.8g\n" \$(printf "%s\n" "\$*" | bc -l); }
· 2019-02-06 23:32:35
• This is the answer to the 0th problem from the python challenge < http://www.pythonchallenge.com/ >. Replace sensible-browser with firefox, w3m or whatever. Show Sample Output

-1
sensible-browser http://www.pythonchallenge.com/pc/def/\$(bc <<< 2^38).html
· 2010-02-02 00:53:18
• This is an "argument calculator" funktion. The precision is set to 4 and you can use dot (.) or comma (,) as decimal mark (which is great for german users with a comma on the numpad).

-1
calc() { echo "scale=4; \${*//,/.}" | bc -l; }
· 2011-10-24 19:58:20
• 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. Show Sample Output

-2
bc
· 2009-03-24 16:19:12
• Of course, this command must be executed at a GRID User Interface lhcb - name of your VO, substitute it with the one you are interested it. Show Sample Output

-2
echo `lcg-infosites --vo lhcb ce | cut -f 1| grep [[:digit:]]| tr '\n' '+' |sed -e 's/\ //g' -e 's/+\$//'`|bc -l
· 2010-11-10 15:06:00
• Probably more trouble than its worth, but worked for the obscure need.

-2
memnum=\$(awk '{ print \$2 }' /proc/meminfo |head -n1); echo "\$memnum / 1024 / 1024" | bc -l
· 2011-11-08 16:28:25
• Broken in two parts, first get the number of cores with cat /proc/cpuinfo |grep proc|wc -l and create a integer sequence with that number (xargs seq), then have GNU parallel loop that many times over the given command. Cheers! Show Sample Output

-2
time cat /proc/cpuinfo |grep proc|wc -l|xargs seq|parallel -N 0 echo "scale=4000\; a\(1\)\*4" '|' bc -l
· 2018-12-06 05:15:24

• -3
paste -sd'+' file|bc -l
· 2011-02-24 03:04:54
• Exit with empty line

-7
read c; while [ -n "\$c" ]; do clear; echo -e "\$c = "\$(echo "\$c" |bc -l)"\n"; read c; done
· 2011-11-13 10:28:40
•  < 1 2 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.

### Check These Out

check open ports without netstat or lsof

The "vorbiscomment" utility lets you update information such as artist names and song and album tags in an Ogg Vorbis file. You can use this command to fix any mistakes that were made when ripping an album.

speedtest

Get an IP address out of fail2ban jail
Removes an iptables rule created by fail2ban. This example shows how to remove a rule for an IP from the fail2ban-SSH chain. Can be used for any service monitored by fail2ban. For more on fail2ban, see http://www.fail2ban.org/wiki/index.php/Main_Page

multiline data block parse and CSV data extraction with perl
extract data in multiline blocks of data with perl pattern matching loop

analyze traffic remotely over ssh w/ wireshark
Please check out my blog article on this for more detail. http://jdubb.net/blog/2009/08/07/monitor-wireshark-capture-real-time-on-remote-host-via-ssh/

Conficker Detection with NMAP

Include a remote file (in vim)
Like vim scp://yourhost//your/file but in vim cmds.

Typing the current date ( or any string ) via a shortcut as if the keys had been actually typed with the hardware keyboard in any application.
That works in all softs, CLI or GUI... I don't want to waste time to all the time typing the same stuff . So, I have that command in my window manager shortcuts ( meta+l ). All the window managers have editable shortcuts AFAIK. If not, or you don't want to use it that way, you can easily use the xbindkeys soft. I you're using kde4, you can run : \$ systemsettings then open "inputs actions" and create a new shortcut. For Gnome take a look there : http://www.cyberciti.biz/faq/howto-create-keyboard-shortcuts-in-gnome/ A more advanced one, with strings and newlines : \$ xvkbd -xsendevent -text "---8

skip broken piece of a loop but not exit the loop entirely
useful for loops like for i in \$(cat list_of_servers); do ssh -q \$i hostname; done if there is an unreachable server, you can just press ctrl + \ to skip that server and continue on with the loop