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.

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



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 grep from sorted by
Terminal - Commands using grep - 1,657 results
svn log fileName|cut -d" " -f 1|grep -e "^r[0-9]\{1,\}$"|awk {'sub(/^r/,"",$1);print "svn cat fileName@"$1" > /tmp/fileName.r"$1'}|sh
2009-05-27 02:11:58
User: fizz
Functions: awk cut grep
Tags: bash svn awk grep

exported files will get a .r23 extension (where 23 is the revision number)

lsof -nP +p 24073 | grep -i listen | awk '{print $1,$2,$7,$8,$9}'
kill_daemon() { echo "Daemon?"; read dm; kill -15 $(netstat -atulpe | grep $dm | cut -d '/' -f1 | awk '{print $9}') }; alias kd='kill_daemon
2009-05-26 20:39:56
User: P17

Just find out the daemon with $ netstat -atulpe. Then type in his name and he gets the SIGTERM.

cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
2009-05-22 22:40:25
User: mohan43u
Functions: cpp grep

will display typedefs, structs, unions and functions declared in 'stdio.h'(checkout _IO_FILE structure). It will be helpful if we want to know what a particular header file will offer to us. Command 'cpp' is GNU's C Preprocessor.

F="$HOME/.moz*/fire*/*/session*.js" ; grep -Go 'entries:\[[^]]*' $F | cut -d[ -f2 | while read A ; do echo $A | sed s/url:/\n/g | tail -1 | cut -d\" -f2; done
2009-05-21 21:58:42
User: b2e
Functions: cut echo grep read sed tail

Tuned for short command line - you can set the path to sessionstore.js more reliable instead of use asterixes etc.

Usable when you are not at home and really need to get your actual opened tabs on your home computer (via SSH). I am using it from my work if I forgot to bookmark some new interesting webpage, which I have visited at home. Also other way to list tabs when your firefox has crashed (restoring of tabs doesn't work always).

This script includes also tabs which has been closed short time before.

expr $(fdisk -s ` grep ' / ' /etc/mtab |cut -d " " -f1`) / 1024
curl -s checkip.dyndns.org | grep -Eo '[0-9\.]+'
2009-05-21 16:12:21
User: haivu
Functions: grep

The curl command retrieve the HTML text containing the IP address. The grep command picks out the IP address from that HTML text.

grep --color=always | less -R
2009-05-20 20:30:19
User: dinomite
Functions: grep less

Get your colorized grep output in less(1). This involves two things: forcing grep to output colors even though it's not going to a terminal and telling less to handle those properly.

netstat -ntlp | grep -w 80 | awk '{print $7}' | cut -d/ -f1
find / -iname '*.pdf' -print -exec pdftotext '{}' - \; | grep --color -i "unix"
grep -lir "some text" *
2009-05-20 19:44:35
User: decept
Functions: grep
Tags: find text

-l outputs only the file names

-i ignores the case

-r descends into subdirectories

find . -name "*.jar" | while read file; do echo "Processing ${file}"; jar -tvf $file | grep "Foo.class"; done
grep -ao -HP "http://[^/]*/" *
2009-05-20 14:45:34
User: binarycodes
Functions: grep

Replace * with any filename matching glob or an individual filename

cat -n FILE | grep -C3 "^[[:blank:]]\{1,5\}NUMBER[[:blank:]]"
2009-05-17 18:19:55
User: lv4tech
Functions: cat grep

This is useful for displaying a portion of a FILE that contains an error at line NUMBER

/sbin/dumpe2fs /dev/hda2 | grep 'Block size'
2009-05-15 22:23:21
User: rez0r
Functions: grep
Tags: size output block

Useful to know, especially if you are dealing with output configurations in block size.

Tested on 'Red Hat'.

svn log | grep "bodge\|fudge\|hack\|dirty"
2009-05-15 09:55:44
User: root
Functions: grep

A good way to understand what you've let yourself in for. Potential project metric could be the count:

svn log | grep -c "bodge\|fudge\|hack\|dirty"
svn st | grep '^\?' | awk '{print $2}' | xargs svn add; svn st | grep '^\!' | awk '{print $2}' | xargs svn rm
2009-05-14 14:34:50
User: stedwick
Functions: awk grep xargs

automatically add and remove files in subversion so that you don't have to do it through the annoying svn commands anymore

curl -s http://checkip.dyndns.org/ | grep -o "[[:digit:].]\+"
grep -i '<searchTerm>\|<someOtherSearchTerm>' <someFileName>
2009-05-11 23:05:54
User: scifisamurai
Functions: grep

This is a simple but useful command to search for multiple terms in a file at once. This prevents you from having to do mutliple grep's of the same file.

echo 2006-10-10 | grep -c '^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'
2009-05-11 22:18:43
User: rez0r
Functions: echo grep

Quick and easy way of validating a date format of yyyy-mm-dd and returning a boolean, the regex can easily be upgraded to handle "in betweens" for mm dd or to validate other types of strings, ex. ip address.

Boolean output could easily be piped into a condition for a more complete one-liner.

curl -s http://bash.org/?random1|grep -oE "<p class=\"quote\">.*</p>.*</p>"|grep -oE "<p class=\"qt.*?</p>"|sed -e 's/<\/p>/\n/g' -e 's/<p class=\"qt\">//g' -e 's/<p class=\"qt\">//g'|perl -ne 'use HTML::Entities;print decode_entities($_),"\n"'|head -1
2009-05-07 13:13:21
User: Iftah
Functions: grep head perl sed

bash.org is a collection of funny quotes from IRC.

WARNING: some of the quotes contain "adult" jokes... may be embarrassing if your boss sees them...

Thanks to Chen for the idea and initial version!

This script downloads a page with random quotes, filters the html to retrieve just one liners quotes and outputs the first one.

Just barely under the required 255 chars :)


You can replace the head -1 at the end by:

awk 'length($0)>0 {printf( $0 "\n%%\n" )}' > bash_quotes.txt

which will separate the quotes with a "%" and place it in the file.

and then:

strfile bash_quotes.txt

which will make the file ready for the fortune command

and then you can:

fortune bash_quotes.txt

which will give you a random quote from those in the downloaded file.

I download a file periodically and then use the fortune in .bashrc so I see a funny quote every time I open a terminal.

for i in *jpg; do jpeginfo -c $i | grep -E "WARNING|ERROR" | cut -d " " -f 1 | xargs -I '{}' find /mnt/sourcerep -name {} -type f -print0 | xargs -0 -I '{}' cp -f {} ./ ; done
2009-05-07 00:30:36
User: vincentp
Functions: cp cut find grep xargs

Find all corrupted jpeg in the current directory, find a file with the same name in a source directory hierarchy and copy it over the corrupted jpeg file.

Convenient to run on a large bunch of jpeg files copied from an unsure medium.

Needs the jpeginfo tool, found in the jpeginfo package (on debian at least).

lsof -i | grep -i estab
find . -name "*.[ch]" -exec grep -i -H "search pharse" {} \;
2009-05-06 15:22:49
User: bunedoggle
Functions: find grep
Tags: find grep

I have a bash alias for this command line and find it useful for searching C code for error messages.

The -H tells grep to print the filename. you can omit the -i to match the case exactly or keep the -i for case-insensitive matching.

This find command find all .c and .h files

awk -F\" '{print $4}' *.log | grep -v "eviljaymz\|\-" | sort | uniq -c | awk -F\ '{ if($1>500) print $1,$2;}' | sort -n
2009-05-05 22:21:04
User: jaymzcd
Functions: awk grep sort uniq

This prints a summary of your referers from your logs as long as they occurred a certain number of times (in this case 500). The grep command excludes the terms, I add this in to remove results Im not interested in.