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 grep from sorted by
Terminal - Commands using grep - 1,622 results
sensors | grep "Core 1" | [[ `sed -e 's/^.*+\([0-9]\{2,3\}\).*(.*/\1/'` -gt 50 ]] && notify-send "Core 1 temperature exceeds 50 degrees"
2009-11-12 21:51:21
Functions: grep sensors

You'll be notified if your core 1 temperature exceeds 50 degrees, you can change the monitored device by editing the "Core 1" or change the critical temperature by editing the "-gt 50" part.

Note: you must have lm-sensors installed and configured in order to get this command working.

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

find -name '*.avi' | while read i ; do echo $(mplayer -identify -frames 0 -vo null -nosound "$i" 2>&1 | grep ID_LENGTH | cut -d= -f2)" ""$i" ;done | sort -k1 -r -n | sed 's/^\([^\ ]*\)\ \(.*\)$/\2:\1/g'
2009-11-09 17:14:59
User: ZungBang
Functions: cut echo find grep read sed sort

handles file names with spaces and colons, fixes sort (numeric!), uses mplayer, same output format as other alternatives

for i in *.avi; do echo -n "$i:";mediainfo $i|head | grep PlayTime | cut -d: -f2 ; done | sort -t: -k2 -r
2009-11-09 12:42:20
User: yooreck
Functions: cut echo grep head sort

Similar but using mediainfo instead of totem-something

for i in *.avi; do echo -n "$i:";totem-gstreamer-video-indexer $i | grep DURATION | cut -d "=" -f 2 ; done | sort -t: -k2 -r
2009-11-09 02:59:53
User: iadbungler
Functions: cut echo grep sort

Sort .avi movies by time length, print the longest first, and so on...

mpg123 `curl -s http://blip.fm/all | sed -e 's#"#\n#g' | grep mp3$ | xargs`
grep -c '^From ' mbox_file
GeoipLookUp(){ curl -A "Mozilla/5.0" -s "http://www.geody.com/geoip.php?ip=$1" | grep "^IP.*$1" | html2text; }
2009-11-06 00:32:27
User: sputnick
Functions: grep
Tags: sed curl

That makes a function you can put in your ~/.bashrc to run it when you need in any term with an IP as argument

ip link show eth0 | grep "link/ether" | awk '{print $2}'
2009-11-05 17:06:15
User: maxmanders
Functions: awk grep link
Tags: mac

...or for a particular interface...

grep "model name" /proc/cpuinfo
2009-11-05 05:23:30
User: getkaizer
Functions: grep
Tags: grep cpuinfo

Extracts the model name of the CPU and displays it on screen.

lynx --dump http://ip.boa.nu|sed -e 's/^[[:space:]]*//' -e 's/*[[:space:]]$//'|grep -v ^$
2009-11-04 22:23:45
User: xeor
Functions: grep sed

For those of us that still uses lynx :)

ip link | grep 'link/ether' | awk '{print $2}'
2009-11-04 19:41:26
User: markdrago
Functions: awk grep link
Tags: mac

I much prefer using /sbin/ip over /sbin/ifconfig for most everything. I find the interface and output to be much more consistent and it has many abilities that ifconfig, route, etc. do not. To get the mac address for only one interface, add 'show dev [interface]' to the 'ip link' part of the command: ip link show dev eth0 | grep 'link/ether' | awk '{print $2}' . Also, both this command and the ifconfig one do not require root access to run, so the sudo is not necessary.

sudo ifconfig -a | grep eth | grep HW | cut -d' ' -f11
ps -ec -o command,rss | grep Stainless | awk -F ' ' '{ x = x + $2 } END { print x/(1024) " MB."}'
2009-11-04 19:01:22
Functions: awk grep ps

Adds up the total memory used by all Stainless processes: 1 Stainless, 1 StainlessManager and 1 StainlessClient per tab open.

ifconfig eth1 | grep inet\ addr | awk '{print $2}' | cut -d: -f2 | sed s/^/eth1:\ /g
2009-11-03 19:26:40
User: TuxOtaku
Functions: awk cut grep ifconfig sed

Sometimes, you don't really care about all the other information that ifconfig spits at you (however useful it may otherwise be). You just want an IP. This strips out all the crap and gives you exactly what you want.

for x in `find /vmfs/volumes/ -name *vmx -exec grep -H linux.iso {} \; |cut -d : -f 1`; do echo $x; grep -i sync $x; done;
2009-10-30 16:19:16
User: uid0
Functions: cut echo grep sync

besure to adjust your find to use to correct location of your VMX files.

for URL in `wget -O - http://api.flickr.com/services/feeds/photos_public.gne?tags=bitch,bw 2>/dev/null | grep -E -o "http[^ ]+?jpg" | grep -v "_m" | uniq | grep -v 'buddy' `; do FILE=`echo $URL | grep -E -o "[0-9a-z_]+\.jpg"`; curl $URL > $FILE; done;
find . -name '*.java' | xargs -L 1 cpp -fpreprocessed | grep . | wc -l
2009-10-29 09:58:43
User: rbossy
Functions: cpp find grep wc xargs

I took java to make the find command simpler and to state that it works for any language supported by cpp.

cpp is the C/C++ preprocessor (interprets macros, removes comments, inserts includes, resolves trigraphs). The -fpreprocessor option tells cpp to assume the input has already been preprocessed so it will only replace comment lines with blank lines.

The -L 1 option tells xargs to launch one process for each line, indeed cpp can only process one file at the time...

TIMEUNIT=$( cat a | grep -n "timescale" | awk -F ":" '{ print $1 } ' )
curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
w3m miip.cl | grep ip
2009-10-26 01:40:37
User: Cont3mpo
Functions: grep

See external ip with w3m, simple and fast.

On a web site from Chile (spanish).

grep test somefile | grep -v -e error -e critical -e warning
2009-10-24 15:58:11
User: pipping
Functions: grep test

You can use -e to pass multiple patterns.

grep 'test' somefile | grep -vE '(error|critical|warning)'
2009-10-23 23:21:36
User: zlemini
Functions: grep

Use multiple patterns with grep -v. So you can print all lines in a file except those containing the multiple patterns you specify.

for i in $(netstat --inet -n|grep ESTA|awk '{print $5}'|cut -d: -f1);do geoiplookup $i;done
2009-10-18 20:41:47
Functions: awk cut grep netstat

Sample command to obtain a list of geographic localization for established connections, extracted from netstat. Need geoiplookup command ( part of geoip package under CentOS)

x=1 ; while [ $x -le 10 ] ; do lynx -dump http://www.alexa.com/siteinfo/http://[YOUR WEBSITE] | grep Global | sed 's/ \|Global\|\,//g' >> /var/log/alexa-stats.txt ; sleep 5h ; done &
2009-10-17 13:48:05
User: felix001
Functions: grep sed sleep

This will record the Alexa Traffic Stats to a file and run every 5 hours.

-- www.fir3net.com --