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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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



Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

Commands using awk from sorted by
Terminal - Commands using awk - 1,216 results
wget -O - http://www.commandlinefu.com/commands/browse/rss 2>/dev/null | awk '/\s*<title/ {z=match($0, /CDATA\[([^\]]*)\]/, b);print b[1]} /\s*<description/ {c=match($0, /code>(.*)<\/code>/, d);print d[1]} ' | grep -v "^$"
2010-06-29 16:22:03
User: nikunj
Functions: awk grep wget
Tags: awk grep meta

A Quick variation to the latest commands list with the new-lines skipped. This is faster to read.

ifconfig eth0 | grep "inet " | cut -d ':' -f2 | awk '{print $1}'
2010-06-29 00:06:08
User: jaimerosario
Functions: awk cut grep ifconfig

I've been using it in a script to build from scratch proxy servers.

free -m | awk '/buffer/ {print $4}'
2010-06-27 23:30:27
User: DaveQB
Functions: awk free
Tags: ram free

Here we instead show a more real figure for how much free RAM you have when taking into consideration buffers that can be freed if needed.

Unix machines leave data in memory but marked it free to overwrite, so using the first line from the "free" command will mostly give you back a reading showing you are almost out of memory, but in fact you are not, as the system can free up memory as soon as it is needed.

I just noticed the free command is not on my OpenBSD box.

free -m | awk '/Mem/ {print $4}'
awk 'BEGIN { ARGV[ARGC++]=ARGV[ARGC-1] } NR!=FNR { if(num==0) num=NR-1; if(FNR<num) {print} else { ORS=""; print } } ' abc1.txt > abc2.txt
ip addr show eth0 |grep 'inet\b' |awk '{print $2}' |sed -r -e 's/\/.*?//g'
ifconfig eth0 | perl -ne "print if m/inet addr:((\d+\.){3})+/" | sed "s/inet addr//" | sed "s/Bcast//" |awk -F: '{print $2}'
2010-06-26 12:07:15
User: aceiro
Functions: awk ifconfig perl sed

only output the ip addres. I put double pipe with sed because not parse with operator OR (|) in redex.

ifconfig eth0 | grep 'HWaddr' | awk '{print $5}' | tr 'a-z' 'A-Z' | sed -e 's/://g'
2010-06-26 05:35:03
User: minigeek
Functions: awk grep ifconfig sed tr

This will get the mac address of the eth0 and change lowercase to uppercase.

The sed command removed the colons.

ifconfig eth0 | grep 'HWaddr' | awk '{print $5}'
/sbin/ifconfig eth0 | grep 'inet6 addr:' | awk {'print $3'}
/sbin/ifconfig eth0 | grep 'inet addr:' | awk {'print $2'} | sed 's/addr://'
ac -d | awk '{h=int($NF); m=($NF-h)*60; s=int((m-int(m))*60); m=int(m); print $0" = "h"h "m"m "s"s "}'
2010-06-24 08:08:41
User: karpoke
Functions: awk
Tags: awk ac

'ac' is included in the package 'acct', which is described as "The GNU Accounting utilities for process and login accounting". Other interesting flags are:

* print statistics for a specified user

ac -d username

* print statistics for all the users

ac -p

With my command, the output is also printed in a sexagesimal, more readable, style.

vimlint(){ eval $(xmllint --noout "$1" 2>&1 | awk -F: '/parser error/{print "vim \""$1"\" +"$2; exit}'); }
2010-06-23 15:55:02
User: putnamhill
Functions: awk eval

Validate a file using xmllint. If there are parser errors, edit the file in vim at the line of the first error.

for pid in `screen -ls | grep -v $STY | grep tached | awk '{print $1;}' | perl -nle '$_ =~ /^(\d+)/; print $1;'`; do screen -x $pid; done
2010-06-22 23:06:31
User: tmsh
Functions: awk grep perl screen

Personally, I save this in a one line script called ~/bin/sci:


for pid in `screen -ls | grep -v $STY | grep tached | awk '{print $1;}' | perl -nle '$_ =~ /^(\d+)/; print $1;'`; do screen -x $pid; done

I also use:

alias scx='screen -x'

alias scl='screen -ls | grep -v $STY'

pvscan | awk '/name_of_vg/ {print $2}' | sed 's/[-|/|]/ /g' | cut -d " " -f7
2010-06-22 16:34:42
User: slashdot
Functions: awk cut sed

This is an easy way to quickly get a status for a device in multipath on SLES systems, as long as the server is configured based on Novell's standards, where multipathed disks are referred to by /dev/disk/by-... tree. Make sure to replace name_of_vg with your Volume Group name.

svn st | awk '{if ($1 ~ "?") print $2}' | xargs svn add
2010-06-19 03:07:26
User: sciurus
Functions: awk xargs
Tags: svn awk

No need for grep, let awk do the match. This will not behave properly if the filenames contains whitespace, which is awk's default field separator.

ps ux|grep <process name>|awk '{print $2}'|xargs -n 1 kill
HISTTIMEFORMAT='' history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head > /tmp/cmds ; gnuplot -persist <<<'plot "/tmp/cmds" using 1:xticlabels(2) with boxes'
2010-06-17 17:38:16
User: narcelio
Functions: awk head sort

This alternative cleans HISTTIMEFORMAT environment variable and calls gnuplot just after /tmp/cmds is closed, to avoid some errors.

dpkg-query -l > 1.lst; sudo apt-get install -y build-essential; ./configure; make; sudo checkinstall -D make install; dpkg-query --list > 2.lst; diff 1.lst 2.lst | grep '^>' | awk '{print $3}' | xargs sudo apt-get remove -y --purge
2010-06-16 22:06:07
User: danlangford

on a dpkg managed system this PATTERN will help you generate .deb files from source AND remove all the dev libs you had to install. i hate cluttering up my machine with rouge packages and headers.

it would be pretty darn easy on rpm systems as well. i just dont have a rpm managed system to test on right now.

NOTE, you sharp ones will notice that it uninstalls the deb you just made! yeah, but the deb is still there to do with it what you want, like re install it. or you can just grep -v after the diff

find . -type d -exec du -sk '{}' \; | awk '($1 < 2048) {print $2}'
2010-06-16 11:53:14
User: putnamhill
Functions: awk du find

Just shortened the awk a bit and removed sed. Edit: I'm assuming there are no spaces in the path. To support white space in pathname try:

awk '($1 < 2048) {sub(/^[0-9]+[ \t]+/,""); print $0}'
find . -type d -exec du -sk '{}' \; | awk '{ if ($1 <2000) print $0 }' | sed 's/^[0-9]*.//'
2010-06-16 09:37:56
User: mtron
Functions: awk du find sed

This command will search all subfolders of the current directory and list the names of the folders which contain less than 2 MB of data. I use it to clean up my mp3 archive and to delete the found folders pipe the output to a textfile & run:

while read -r line; do rm -Rv "$line"; done < textfile
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head > /tmp/cmds | gnuplot -persist <(echo 'plot "/tmp/cmds" using 1:xticlabels(2) with boxes')
2010-06-13 23:35:13
User: sthrs
Functions: awk echo head sort

Plot your most used commands with gnuplot.

while true;do clear;echo -n Current\ `grep voltage /proc/acpi/battery/BAT0/state | awk '{print $2" "$3" "$4}'`;for i in `seq 1 5`;do sleep 1;echo -n .;done;done
acpi -b | sed 's/,//g' | awk '{print $3}'
2010-06-11 05:32:57
User: dbbolton
Functions: acpi awk sed
Tags: battery acpi

This prints "Charging" or "Discharging". Obviously, this will indicate the status of the AC adapter. The awk part could be from 1-6. I removed the comma because it is useless when only looking at one element of the output array. See acpi(1) for more info.

aptitude remove $(dpkg -l|egrep '^ii linux-(im|he)'|awk '{print $2}'|grep -v `uname -r`)
2010-06-10 21:23:00
User: dbbolton
Functions: awk egrep grep

This should do the same thing and is about 70 chars shorter.