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.

If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

Universal configuration monitoring and system of record for IT.

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 awk from sorted by
Terminal - Commands using awk - 1,207 results
awk 'NR==2 {print $1}' /proc/net/arp
ifconfig -a| awk 'BEGIN{FS="[ :]+"} /Bcast/{print $4}'
ifconfig -a|grep Bcast:|cut -d\: -f2|awk '{print $1}'
/usr/sbin/ifconfig -a|awk -F" " 'NR==4{print $2}'
curl -s 'xkcd.com' | awk -F\" '/^<img/{printf("<?xml version=\"1.0\"?>\n<xkcd>\n<item>\n <title>%s</title>\n <comment>%s</comment>\n <image>%s</image>\n</item>\n</xkcd>\n", $6, $4, $2)}'
2009-12-03 19:49:37
User: putnamhill
Functions: awk

I wasn't sure how to display the image, so I thought I'd try xml for a different twist.

lynx --dump --source http://www.xkcd.com | grep `lynx --dump http://www.xkcd.com | egrep '(png|jpg)'` | grep title | cut -d = -f2,3 | cut -d '"' -f2,4 | sed -e 's/"/|/g' | awk -F"|" ' { system("display " $1);system("echo "$2); } '
2009-12-03 18:53:57
Functions: awk cut egrep grep

Same thing just a different way to get there. You will need lynx

dd if=/dev/zero of=/fs/to/fill/dummy00 bs=8192 count=$(df --block-size=8192 / | awk 'NR!=1 {print $4-100}')
2009-12-03 15:20:18
User: arcege
Functions: awk dd df
Tags: dd df

For disk space constraint testing. Leaves a little space available for creating temp files, etc. Easily free up the used disk space again by deleting the dummy00 file. Can tailor the testing by building smaller 'blocks' to suit the needs of the testing.

WARNING: do not do this to the '/' (root) filesystem unless you know what you are doing... on some systems it could crash the OS.

MYSQL="mysql -h HOST -u USERNAME -pPASSWORD -D DB_NAME" ; $MYSQL -BNe "show tables" | awk '{print "set foreign_key_checks=0; drop table `" $1 "`;"}' | $MYSQL unset MYSQL
awk '/<link>/{gsub(/.*<link>|<\/link>.*/,"");print "<li><a href=\042"$0"\042> "t"</a>" } /<title>/{gsub(/.*<title>|<\/title>.*/,"");t=$0 }' file
2009-11-28 15:49:06
Functions: awk

you can just use one awk script to parse the rss feed. No need to pipe so many awk's and sed's. Its ugly and inefficient.

egrep "<link>|<title>" recenttracks.rss | awk 'ORS=NR%2?" ":"\n"' | awk -F "</title>" '{print $2, $1}' | sed -e 's/\<link\>/\<li\>\<a href\=\"/' -e 's/\<\/link\>/\">/' -e 's/\<title\>//' -e 's/$/\<\/a\>\<\/li\>/g' -e '1,1d' -e 's/^[ \t]*//'
2009-11-28 13:19:05
User: HerbT
Functions: awk egrep sed

Quick and kludgy rss parser for the recent tracks rss feed from last.fm. Extracts artist and track link.

cho "(Something like http://foo.com/blah_blah)" | awk '{for(i=1;i<=NF;i++){if($i~/^(http|ftp):\/\//)print $i}}'
2009-11-28 03:31:41
Functions: awk

don't have to be that complicated

netstat | awk '/EST/{print $5}' | sort
netstat | grep EST | awk '{print $5}' | sort
2009-11-24 13:38:28
User: unixoid
Functions: awk grep netstat

Sometimes I need a quick visual way to determine if there is a particular server who is opening too many connections to the database machine.

ls -l `ls -l |awk '/^l/ {print $8}'`
2009-11-23 16:02:18
User: yooreck
Functions: awk ls

ls -l may vary depending on operating system, so "print $8" may have to be changed

awk '/q=/{print $11}' /var/log/httpd/access_log.4 | awk -F 'q=' '{print $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1
cat /var/log/httpd/access_log | grep q= | awk '{print $11}' | awk -F 'q=' '{print $2}' | sed 's/+/ /g;s/%22/"/g;s/q=//' | cut -d "&" -f 1 | mail [email protected] -s "[your-site] search strings for `date`"
2009-11-22 03:03:06
User: isma
Functions: awk cat grep sed strings

It's not a big line, and it *may not* work for everybody, I guess it depends on the detail of access_log configuration in your httpd.conf. I use it as a prerotate command for logrotate in httpd section so it executes before access_log rotation, everyday at midnight.

ls -l | awk '$5 > 1000000' | sort -k5n
find <dir> -printf '%p : %A@\n' | awk '{FS=" : " ; if($2 < <time in epoc> ) print $1 ;}' | xargs rm --verbose -fr ;
2009-11-20 16:31:58
User: angleto
Functions: awk find rm xargs

remove files with access time older than a given date.

If you want to remove files with a given modification time replace %A@ with %T@. Use %C@ for the modification time.

The time is expressed in epoc but is easy to use any other format.

cat *.c | { printf "se te du\nplot '-' t '' w dots\n"; tr '[[:upper:]]' '[[:lower:]]' | tr -s [[:punct:][:space:]] '\n' | sort | uniq -c | sort -nr | head -n 100 | awk '{print $1}END{print "e"}'; } | gnuplot
2009-11-20 14:53:26
User: taliver
Functions: awk cat head printf sort tr uniq

Uses the dumb terminal option in gnuplot to plot a graph of frequencies. In this case, we are looking at a frequency analysis of words in all of the .c files.

awk '{print $1}' "/proc/modules" | xargs modinfo | awk '/^(filename|desc|depends)/'
for item in *;do echo -n "$item - ";find "$item" -type f -print0 | xargs -0 file -iNf - | grep video | cut -d: -f1 | xargs -d'\n' /usr/share/doc/mplayer/examples/midentify | grep ID_LENGTH | awk -F= '{sum+=$2} END {print(sum/60)}'; done | grep -v ' - 0$'
2009-11-19 06:28:15
User: jnash
Functions: awk cut echo file grep xargs

I know this has been beaten to death but finding video files using mime types and printing the "hours of video" for each directory is (IMHO) easier to parse than just a single total. Output is in minutes.

Among the other niceties is that it omits printing of non-video files/folders

PS: Barely managed to fit it within the 255 character limit :D

/usr/share/mplayer/midentify.sh `find . -name "*.avi" -print` | grep ID_LENGTH | awk -F "=" '{sum += $2} END {print sum/60/60; print "hours"}'
2009-11-17 03:33:20
User: equant
Functions: awk grep

midentify.sh is part of mplayer, but you might have to locate it on your box.

curl http://www.spam.la/?f=sender | grep secs| awk '{print; exit}' | osd_cat -i 40 -d 30 -l 2
2009-11-12 21:33:06
User: m33600
Functions: awk grep

I have a custmer's Geovision DVR installed on a closed proxi (only logme-in reaches it).

I have to check for reliability but logmein hangs and is too slow a process

I made the Geovision software send e-mail every minute to the www.spam.la site.

All this script does is to retrieve the e-mail header from spam.la ( no login!), filtering sender, stopping at the first occurrence of the word "secs" ( the age of the last e-mail ).

The result is the age of the sender's last e-mail, tiny published on top of my screen once a minute.

I can refresh www.spam.la via web browser, but have other things to do.

I use it inside Kalarm ( kde task schedule ) set to 1 minute repeat.

It can be done without kalarm, using Watch outside the script.

Try it out now using my account = geo1 ( change sender by geo1 in this script)

Needs curl , osd-bin

for i in `cat /etc/passwd | awk -F : '{ print $1 }';`; do passwd -e $i; done
ompload() { curl -# -F file1=@"$1" http://ompldr.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;print}';}
2009-11-07 20:56:52
User: eightmillion
Functions: awk

This function uploads images to http://omploader.org and then prints out the links to the file.

Some coloring can also be added to the command with:

ompload() { curl -F file1=@"$1" http://omploader.org/upload|awk '/Info:|File:|Thumbnail:|BBCode:/{gsub(/<[^<]*?\/?>/,"");$1=$1;sub(/^/,"\033[0;34m");sub(/:/,"\033[0m:");print}';}