### All commands (13,009) the last day the last week the last month all time sorted by date votes

• Calculates nth Fibonacci number for all n>=0, (much faster than matrix power algorithm from http://everything2.com/title/Compute+Fibonacci+numbers+FAST%2521 ) n=70332 is the biggest value at http://bigprimes.net/archive/fibonacci/ (corresponds to n=70331 there), this calculates it in less than a second, even on a netbook. UPDATE: Now even faster! Uses recurrence relation for F(2n), see http://en.wikipedia.org/wiki/Fibonacci_number#Matrix_form n is now adjusted to match Fn at wikipedia, so bigprimes.net table is offset by 1. UPDATE2: Probably fastest possible now ;), uses a simple monoid operation: uses monoid (a,b).(x,y)=(ax+bx+ay,ax+by) with identity (0,1), and recursion relations: F(2n-1)=Fn*Fn+F(n-1)*F(n-1) F(2n)=Fn*(2*F(n-1)+Fn) then apply fast exponentiation to (1,0)^n = (Fn,F(n-1)) . Note that: (1,0)^-1=(1,-1) so (a,b).(1,0) = (a+b,a) and (a,b)/(1,0)=(a,b).(1,0)^-1=(b,a-b) So we can also use a NAF representation to do the exponentiation,http://en.wikipedia.org/wiki/Non-adjacent_form , it's also very fast (about the same, depends on n): `time echo 'n=70332;m=(n+1)/2;a=0;b=1;i=0;while(m>0){z=0;if(m%2)z=2-(m%4);m=(m-z)/2;e[i++]=z};while(i--){c=a*a;a=c+2*a*b;b=c+b*b;if(e[i]>0){t=a;a+=b;b=t};if(e[i]<0){t=a;a=b;b=t-b}};if(n%2)a*a+b*b;if(!n%2)a*(a+2*b)' | bc` Show Sample Output

-135
time echo 'n=70332;m=(n+1)/2;a=0;b=1;i=0;while(m){e[i++]=m%2;m/=2};while(i--){c=a*a;a=c+2*a*b;b=c+b*b;if(e[i]){t=a;a+=b;b=t}};if(n%2)a*a+b*b;if(!n%2)a*(a+2*b)' | bc
· 2009-09-10 08:58:47
• This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file. * Without the break statement, the select command will loop forever * Setting the PS3 prompt is optional * If the user types an invalid choice (such as the letter q), then the variable \$f will become an empty string. * For more information, look up the bash's select command Show Sample Output

8
PS3="Enter a number: "; select f in *;do \$EDITOR \$f; break; done
· 2009-09-10 06:04:42
• This command displays a list of lines that are longer than 72 characters. I use this command to identify those lines in my scripts and cut them short the way I like it.

16
awk 'length>72' file
· 2009-09-10 05:54:41

• 8
exiftool -DateTimeOriginal='2009:01:01 02:03:04' file.jpg
· 2009-09-10 03:56:08
• It's hard to beat C. This is just slightly faster than the bc version on my machine. real 0m26.856s user 0m25.030s sys 0m0.024s Requirements: libgmp headers, gcc. Show Sample Output

-5
gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h> ... SEE SAMPLE OUTPUT FOR FULL COMMAND
· 2009-09-10 02:10:46
• Using avidemux to convert multiple files that are in the folder where the command was executed.

5
for i in `ls`;do avidemux --video-codec Xvid4 --load \$i --save \$i.mp4 --quit; done
· 2009-09-10 01:38:42
• Display man page in plain text

-12
man bash | col -b
· 2009-09-10 00:45:27
• for bash commands don't use man use help

-8
help
· 2009-09-10 00:43:31
• Overwrites the boot sector. Since this doesn't overwrite any data, you can usually recover by re-creating the partition table exactly the same as before you zeroed it. This can also help sometimes if you install a new drive in a Windows machine which can't read it.

2
dd if=/dev/zero of=/dev/fd0 bs=512 count=1
· 2009-09-09 23:43:22
• notice what happens when there is more than one unread message in a thread... also people please dont hardcode the password when you use curl. Leave it out and curl will ask you when it runs. Please...?

-6
curl -u username --silent "https://mail.google.com/mail/feed/atom" | perl -ne 'print "\t" if /<name>/; print "\$2\n" if /<(title|name)>(.*)<\/\1>/;
· 2009-09-09 23:25:05

• 2
iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source IP_TO_ROUTE_THROUGH
· 2009-09-09 19:45:32
• This command allow you to ignore certain directories on SVN commands, like SVN STATUS. It is sad see a lot of temporary files from templates_c for each "svn status", no? ;-) This works only on directories under revision control.

5
svn propset svn:ignore "*" tool/templates_c; svn commit -m "Ignoring tool/templates_c"
· 2009-09-09 19:10:03
• This helped me find a botnet that had made into my system. Of course, this is not a foolproof or guarantied way to find all of them or even most of them. But it helped me find it.

11
cat /var/lib/dpkg/info/*.list > /tmp/listin ; ls /proc/*/exe |xargs -l readlink | grep -xvFf /tmp/listin; rm /tmp/listin
· 2009-09-09 18:09:14

• -19
explorer .
· 2009-09-09 15:27:27

• 0
ack -ai 'searchterm'
· 2009-09-09 14:05:27
• Force the user you want to watch doing things into doing his things in a screen session. Then simply attach yourself to that session with the command shown above. Works only if you are on the same machine, of course

5
screen -x
· 2009-09-09 11:30:56
• Opens a file or URL in the user's preferred application.

2
xdg-open .
· 2009-09-09 07:20:32
• OS: Debian based (or those that use dpkg) Equivalent to doing a dpkg -S on each file in \$PATH, but way faster. May report files generated though postinstall scripts and such. For example . It will report /usr/bin/vim .. which is not not a file installed directly by dpkg, but a link generated by alternatives hooks

0
echo -e "\${PATH//://\n}" >/tmp/allpath; grep -Fh -f /tmp/allpath /var/lib/dpkg/info/*.list|grep -vxh -f /tmp/allpath >/tmp/installedinpath ; find \${PATH//:/ } |grep -Fxv -f /tmp/installedinpath
· 2009-09-09 05:33:14

• -1
gnome-open .
· 2009-09-09 05:09:51
• Connect to a machine running ssh using mac address by using the "arp" command Show Sample Output

8
ssh root@`for ((i=100; i<=110; i++));do arp -a 192.168.1.\$i; done | grep 00:35:cf:56:b2:2g | awk '{print \$2}' | sed -e 's/(//' -e 's/)//'`
· 2009-09-09 04:32:20
• Removes trailing newline; colon becomes record separator and newline becomes field separator, only the first field is ever printed. Replaces empty entries with \$PWD. Also prepend relative directories (like ".") with the current directory (\$PWD). Can change PWD with env(1) to get tricky in (non-Bourne) scripts. Show Sample Output

-2
echo src::\${PATH} | awk 'BEGIN{pwd=ENVIRON["PWD"];RS=":";FS="\n"}!\$1{\$1=pwd}\$1!~/^\//{\$1=pwd"/"\$1}{print \$1}'
· 2009-09-09 04:03:46
• This version uses Pipes, but is easier for the common user to grasp... instead of using sed or some other more complicated method, it uses the tr command Show Sample Output

15
echo \$PATH | tr \: \\n
· 2009-09-09 02:10:04

• -9
nautilus `pwd`
· 2009-09-09 00:23:33

• 6
zip -r foo.zip DIR -x "*/.svn/*"
· 2009-09-08 14:43:58

• 0
find . -not \( -name .svn -prune \) -type f | xargs zip XXXXX.zip
· 2009-09-08 12:47:37
• ‹ First  < 403 404 405 406 407 >  Last ›

### 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.