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,661 results
svn status | grep '^?' | awk '{ print $2; }' | xargs svn add
2009-04-10 21:55:37
Functions: awk grep xargs
Tags: svn awk xargs

Lists the local files that are not present in the remote repository (lines beginning with ?)

and add them.

identify -verbose *.jpg|grep "\(Image:\|Resolution\)"
#!/bin/sh for dir in `ls -A | grep -v .sh`; do chown -R $dir:$dir $dir done
function jumpTo { xmms2 jump `xmms2 list | grep -i '$1' | head -n 1 | tail -n 1 | sed -re 's@.+\[(.+)/.+\] (.+)@\1@'`; }
2009-04-10 13:43:57
User: pyrho
Functions: grep head sed tail
Tags: xmms2


Declare this function in your Shell, then use it like this:

> jumpTo foo

The script will search for the 'foo' pattern in your current xmms2 playlist (artist or songname), and play the first occurence of it !

svn info | grep '^URL:' | egrep -o '(tags|branches)/[^/]+|trunk' | egrep -o '[^/]+$'
2009-04-09 20:08:45
User: isaacs
Functions: egrep grep info
Tags: svn grep

Get the svn info, grep for the "URL" of the repository, pull out the tag/branch/trunk, and then just show the helpful/meaningful bit.

grep -r "mystring" . |uniq | cut -d: -f1 | xargs sed -i "s/mystring//"
2009-04-09 12:49:01
Functions: cut grep sed uniq xargs

Linux : these script enable you to edit multiple files and remove exact phrase from multiple files

grep "install " /var/log/dpkg.log | awk '{print $4}' | xargs apt-get -y remove --purge
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
2009-04-04 01:41:48
User: peterc
Functions: grep sudo tcpdump

Replace "en1" with your network interface (on OS X, usually en0, en1, eth0, etc..)

dmesg | grep cpu
2009-04-03 01:57:04
User: kingji
Functions: dmesg grep
Tags: cpus

get cpu info from dmesg

history | grep ssh
2009-04-03 01:35:52
User: haivu
Functions: grep
Tags: bash csh

After seeing the command you wish to repeat, just invoke it using the ! syntax.

ls -l | grep ^l
2009-04-02 17:47:36
User: haivu
Functions: grep ls
Tags: ls

Shows all linked file and destinations. The 'ls -l' command lists the files in long (1 file per line) format, and the grep command displays only those lines that starts with an l (lower case L) -- a linked file.

Updated: Remove reference to hard links because this command does not apply to hard link as others kindly pointed out.

read -p 'Username: ' u;sudo -H -u $u xauth add $(xauth list|grep :$(echo ${DISPLAY: -4:2}));sudo su - $u
u=`curl -d 'dl.start=Free' $(curl $1|perl -wpi -e 's/^.*"(http:\/\/rs.*)" method.*$/$1/'|egrep '^http'|head -n1)|grep "Level(3) \#2"|perl -wpi -e 's/^.*(http:\/\/rs[^\\\\]*).*$/$1/'`;sleep 60;wget $u
while true; do ifconfig eth0 | grep "inet addr:"; sleep 60; done;
2009-04-01 19:29:28
User: bandit36
Functions: grep ifconfig sleep
Tags: script while loop

You can use this to loop any command to periodically see the output.

while true; do [YOUR COMMAND HERE]; sleep [# of seconds]; done;

Alternatively, you can put it in a simple shell script to save typing!


while true; do $1; sleep $2; done;

/path/to/script.sh "ifconfig eth0 | grep 'inet addr:'" 60
find . -name "*.py" -exec grep -n -H -E "^(import|from) math" {} \;
ssh -vN hostname 2>&1 | grep "remote software version"
2009-03-31 18:28:41
User: sud0er
Functions: grep hostname ssh
Tags: ssh

I used this to confirm an upgrade to an SSH daemon was successful

date +%m/%d/%y%X|tr -d 'n' >>datemp.log&& sensors|grep +5V|cut -d "(" -f1|tr -d 'n'>> datemp.log && sensors |grep Temp |cut -d "(" -f1|tr -d 'n'>>datemp.log
2009-03-31 18:13:23
User: f241vc15
Functions: cut date grep sensors tr
cat datemp.log


Sys Temp: +11.0?C

CPU Temp: +35.5?C

AUX Temp: +3.0?C

find . -type f -exec grep StringToFind \{\} --with-filename \;|sed -e '/svn/d'|sed -e '/~/d'
2009-03-31 18:09:31
User: f241vc15
Functions: find grep sed

Look for a string in one of your codes, excluding the files with svn and ~ (temp/back up files). This can be useful when you're looking for a particular string in one of your source codes for example, inside a directory which is under version control (e.g. svn), removing all the annoying files with ~ (tilde) from the search. you can even change the command after -exec to delete (rm) or view (cat) files found by 'find' for example

cat /var/log/secure | grep smtp | awk '{print $9}' | cut -f2 -d= | sort | uniq -c | sort -n | tail
2009-03-30 15:49:54
User: empulse
Functions: awk cat cut grep sort uniq

Searches /var/log/secure for smtp connections then lists these by number of connections made and hosts.

cat /var/log/secure | grep sshd | grep Failed | sed 's/invalid//' | sed 's/user//' | awk '{print $11}' | sort | uniq -c | sort -n
2009-03-30 15:48:24
User: empulse
Functions: awk cat grep sed sort sshd uniq

Searches the /var/log/secure log file for Failed and/or invalid user log in attempts.

svn rm `svn status | grep "\!" | cut -c 8-`
2009-03-29 13:28:55
User: benschw
Functions: cut grep rm
Tags: svn

If (when) you forget to "svn rm" files from your repository, use this to let your repository know you want those files gone. Of course this works with adding and reverting too.

< /path/to/file.txt grep foo
2009-03-29 02:43:40
User: atoponce
Functions: grep

Several times, I find myself hitting my up arrow, and changing the search term. Unfortunately, I find myself wasting too much time typing:

grep kernel /var/log/messages

Redirecting STDIN allows me to put the search term at the end so I less cursor movement to change what I'm searching for:

< /var/log/messages grep kernel

If you're using the emacs keyboard binding, then after you press your up arrow, press CTRL+w to erase the word.

If this has already been submitted, I couldn't find it with the search utility.

rpm -q kernel-2* | grep -v $(uname -r) | xargs yum erase -y
2009-03-28 21:41:15
User: Nick
Functions: grep rpm uname xargs

On Fedora clean the boot directory; erase older kernel

service --status-all | grep running
2009-03-27 19:53:30
User: Williebee
Functions: grep

A quick way to list services running

perl -pi -e 's/foo/bar/g' $(grep -rl foo ./*)
2009-03-27 17:21:35
User: dopeman
Functions: grep perl
Tags: perl

This command will replace all instances of 'foo' with 'bar' in all files in the current working directory and any sub-directories.