### Commands using echo (1,385) the last day the last week the last month all time sorted by date votes

• search argument in PATH accept grep expressions without args, list all binaries found in PATH Show Sample Output

-1
function sepath { echo \$PATH |tr ":" "\n" |sort -u |while read L ; do cd "\$L" 2>/dev/null && find . \( ! -name . -prune \) \( -type f -o -type l \) 2>/dev/null |sed "s@^\./@@" |egrep -i "\${*}" |sed "s@^@\$L/@" ; done ; }
· 2009-09-11 15:03:22
• Define a function `vert () { echo \$1 | grep -o '.'; }` Use it to print some column headers `paste <(vert several) <(vert parallel) <(vert vertical) <(vert "lines of") <(vert "text can") <(vert "be used") <(vert "for labels") <(vert "for columns") <(vert "of numbers")` Show Sample Output

12
echo "vertical text" | grep -o '.'
· 2009-09-11 03:45:04
• EDIT: Trolling crap removed ;) takes approx 6 secs on a Core 2 Duo @ 2GHz, and 15 secs on atom based netbooks! 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=1000000;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

-134
time echo 'n=1000000;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 09:00:44
• 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
• 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
• 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

• 0
prev=0;next=1;echo \$prev;while(true);do echo \$next;sum=\$((\$prev+\$next));prev=\$next;next=\$sum;sleep 1;done
· 2009-09-06 09:38:10
• [Note: This command needs to be run as root]. If you are downloading something large at night, you can start wget as a normal user and issue the above command as root. When the download is done, the computer will automatically go to sleep. If at any time you feel the computer should not go to sleep automatically(like if you find the download still continuing in the morning), just create an empty file called nosleep in /tmp directory.

1
while [ -n "`pgrep wget`" ]; do sleep 2 ;done; [ -e "/tmp/nosleep"] || echo mem >/sys/power/state
· 2009-09-06 05:51:20

• -1
echo capitalize | { dd bs=1 count=1 conv=ucase 2> /dev/null; cat ;}
· 2009-09-05 01:49:53
• A very simple command to send a signed and encrypted message from the command line using GPG Keys

4
echo "SECRET MESSAGE" | gpg -e --armor -s | sendmail USER@DOMAIN.COM
· 2009-09-04 20:47:12
• Based on the MrMerry one, just add some visuals to differentiate files and directories

3
du -a --max-depth=1 | sort -n | cut -d/ -f2 | sed '\$d' | while read i; do if [ -f \$i ]; then du -h "\$i"; else echo "\$(du -h --max-depth=0 "\$i")/"; fi; done
· 2009-09-03 20:43:43
• Based on the MrMerry one, just add some visuals and sort directory and files

2
find . -maxdepth 1 -type d|xargs du -a --max-depth=0|sort -rn|cut -d/ -f2|sed '1d'|while read i;do echo "\$(du -h --max-depth=0 "\$i")/";done;find . -maxdepth 1 -type f|xargs du -a|sort -rn|cut -d/ -f2|sed '\$d'|while read i;do du -h "\$i";done
· 2009-09-03 20:33:21

• -8
echo \$((3.0/5.0))
· 2009-09-03 16:35:09
• another possibility

0
· 2009-09-03 10:37:57
• using awk missed the last char thanks @Josay Show Sample Output

-1
echo sortmeplease | awk '{l=split(\$1,a,"");asort(a);while(x<=l){printf "%s",a[x];x++ }print "";}'
· 2009-09-03 10:22:39
• Can change language and speed, see espeak man page for options. (Install espeak in your linux distro via yum or apt-get) For insomniacs you may need to enclose in a while true; do ...; done loop ;) Show Sample Output

6
echo {1..199}" sheep," | espeak -v english -s 80
· 2009-09-03 10:08:12
• Sorts a character string, using common shell commands. Show Sample Output

1
echo sortmeplease | grep -o . | sort | tr -d '\n'; echo
· 2009-09-03 00:52:49
• using bc is for sissies. dc is much better :-D Polish notation will rule the world... Show Sample Output

2
echo "5 k 3 5 / p" | dc
· 2009-09-03 00:21:54

• -1
for dnsREC in \$(curl -s http://www.iana.org/assignments/dns-parameters |grep -Eo ^[A-Z\.]+\ |sed 's/TYPE//'); do echo -n "\$dnsREC " && dig +short \$dnsREC IANA.ORG; done
· 2009-09-01 03:11:18
• you can also run "xmms2 pause & at now +5min

2
xmms2 pause && echo "xmms2 play" | at now +5min
· 2009-08-30 04:35:10
• Shorter version. Show Sample Output

14
echo "\${PATH//:/\$'\n'}"
· 2009-08-26 23:12:05
• If you need to ssh into a computer on the local network but you're unsure of the ip to use, then ping them and see if you get a response. If you do, print out the address you got it from. Adjust the range to suit your network.

-2
for i in 192.168.1.{61..71};do ping -c 1 \$i &> /dev/null && echo \$i;fi;done
· 2009-08-26 06:04:24
• Nice little alarm clock to wake you up on time (hopefully). You can also do 'echo "vlc path/to/song" | at 6:00

1
echo "xmms2 play" | at 6:00
· 2009-08-26 04:20:24
• this works on Solaris, so not better than the "only-GNU"-tool :-( I think, there is no one-liner for this, that will work on all *nix-es Show Sample Output

0
· 2009-08-25 12:17:01
• ‹ First  < 45 46 47 48 49 >  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.

Binary clock
__ 4