Reading digg today I discovered this list of Linux One Liners claimed to be the "best". However, it's far from best, and simply downright pathetic.

I'll go over each of these so called best one liners and improve on them significantly. For the sake of brevity, I'll only list the command, not the full description.

date | awk -F : '{ print $1 ":" $2 }' | awk '{ print $1 " " $2 " " $3 }' This is just dumb, date prints the date, as in the example: Sat Jan 3 05:16:06 EST 2004. The first pipe to awk outputs Sat Jan 3 05:16. The second pipe to awk prints Sat Jan 3. This would have the exact same effect if the first pipe to awk were entirely removed.

ping -w2 | grep "packets transmitted," | awk '{print $6}' | awk -F% '{print $1 " percent lost packets, duder"}' This one is rather pathetic. First of all, ping under Linux runs forever, so you'll never get an output. Secondly, the author is claiming awk to be a great tool, and it is. However he doesn't understand it in the slightest. Again there's an extra call to awk, but to compound things there's a completely unneccessary call to grep. To make matters worse, he's striping "% packet loss" from the output and adding "percent lost packets, duder" in the command line. I fail to understand how this is the slightest bit helpfu. Try this instead: ping -c 2 | awk -F , '/packets/ {print $3}'.

ps -ef | grep ppp | awk '{ print $2 }' | xargs kill -9 Apparently he's never heard of the killall command. A much simpler one liner is killall -9 pppd.

ls -1 /bin | xargs -l1 whatis 2>/dev/null | grep -v "nothing appropriate" > binhelp.txt This one isn't so bad, but it's still chock full of pointlessness. Let's break it down. First of all, ls -1 is redundant. -1 is implied whenever the output is not STDOUT. Second, xargs -l1 whatis 2>/dev/null, using -l1 is unneccessary, since whatis can handle multiple input arguements and handles them correctly. Third, sending error output to /dev/null while a noble attempt, whatis should only produce errors if there's a permissions or disk error on the whatis database which will make this whole excercise pretty useless. Finally, why send all the output to a text file? That means you type grep foo binhelp.txt instead of whatis foo when you want to find out what a command does. Plus, the whatis keeps itself updated and your text file wont. For something useful, run this command: whatis /bin/* | lp.

grep -i href Bash.html | grep -v '#' | awk -F\" '{ print "" $2 }' | xargs -l1 wget -U mozilla This one is the most correct, if not having a very fine point to it. Once again, the first grep should be incorporated into the awk command.

Amazingly with the previos crap, he manages to get the if, $RANDOM and for right, then goes right back to idiotic. To count the number of files in a directory he suggest a for loop, then ls /mnt/cdrom/* | grep -c . and finally ls | cat -n. Ever hear of wc and its -l switch? Oh, and ls * piped to anything to count the number of files will give wrong results if there are any directories. Use ls -d instead.