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



Commands using find from sorted by
Terminal - Commands using find - 1,081 results
rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing
2010-03-23 21:33:44
User: hhanff
Functions: find grep rm

The command first deletes any old playlist calles playlist.tmp under /tmp. After that it recursively searches all direcotries under ~/mp3 and stores the result in /tmp/playlist.tmp. After havin created the playlist, the command will execute mplayer which will shuffle through the playlist.

This command is aliased to

m is aliased to `rm -rf /tmp/playlist.tmp && find ~/mp3 -name *.mp3 > /tmp/playlist.tmp && mplayer -playlist /tmp/playlist.tmp -shuffle -loop 0 | grep Playing'

in my ~/.bashrc.

find . -type d -empty -delete
find . -depth -type d -empty -exec rmdir -v {} \;
find . -type d | tac | xargs rmdir 2> /dev/null
2010-03-23 11:54:38
User: drmaciver
Functions: find rmdir tac xargs

Remove all empty directories below the current directory. If directories become empty as the results of this, remove those too.

find . -type f -name '*.mp3' -execdir mp3gain -a '{}' +
2010-03-21 22:23:44
Functions: find

This normalizes volume in your mp3 library, but uses mp3gain's "album" mode. This applies a gain change to all files from each directory (which are presumed to be from the same album) - so their volume relative to one another is changed, while the average album volume is normalized. This is done because if one track from an album is quieter or louder than the others, it was probably meant to be that way.

find /dev/ -name random -exec bash -c '[ -r $0 -a -w $0 ] && dd if=$0 | sort | dd of=$0' {} \;
find ${PATH//:/ } -name \*bash\*
2010-03-16 04:26:27
Functions: find

Searches your $PATH for whatever you substitute for bash, though not sure if this will work if you substitute a different shell for bash!

find . -iname '*.mp3' | while read song; do mpg321 ${song} -w - | oggenc -q 9 -o ${song%.mp3}.ogg -; done
2010-03-14 11:34:35
User: renich
Functions: find mpg321 read
Tags: ogg mpg321

This is not recommended... lossy -> lossy = lossier.

Still, you can do it! ;)

pattern='regexp_pattern'; find . -type f -perm +220 ! -name '*.bak' -print0 | xargs -0 egrep -lZ $pattern | xargs -0 sed -i.bak -e "/$pattern/d"
find . -name '*.[c|h]pp' -o -name '*.[ch]' -type f
2010-03-11 01:22:06
User: lucasrangit
Functions: find

Find C/C++ source files and headers in the current directory.

alias busy='my_file=$(find /usr/include -type f | sort -R | head -n 1); my_len=$(wc -l $my_file | awk "{print $1}"); let "r = $RANDOM % $my_len" 2>/dev/null; vim +$r $my_file'
2010-03-09 21:48:41
User: busybee
Functions: alias awk find head sort vim wc

This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim. Drop this in your .bash_aliases and make sure that file is initialized in your .bashrc.

gofuckanalytics() { echo "DELETE FROM moz_cookies WHERE name LIKE '__utm%';" | sqlite3 $( find ~/.mozilla -name cookies.sqlite ) }
2010-03-07 09:16:14
User: meathive
Functions: echo find

See http://code.google.com/apis/analytics/docs/concepts/gaConceptsCookies.html if you are unclear about the Google Analytics cookie system. If Firefox is your daily browser, be a good Orwellian and run this command regularly.

If you see, 'SQL error near line 1: database is locked', close Firefox and run again.

while read f;do echo "$f";done < <(find .)
2010-03-02 14:22:22
Functions: echo find read

Read all contents from current directory and display to stdout.

find . |while read f;do echo "$f";done
2010-03-02 14:21:15
Functions: echo find read

Read all contents from current directory and display it on stdout.

find -name ".php" -exec perl -pi -e 's/search/replace/g/' {} \;
find . type f -exec echo http://exg.com/{} \; > file
2010-03-02 14:18:01
Functions: echo find type

find all files in cur dir add to url and append to file

find -type f -exec mv {} . \;
2010-03-02 07:09:45
User: and3k
Functions: find mv

Find every file and move it to current directory.

find . -type f -exec sed -i 's/gw10./gw17./g' {} \;
find . -type d -name .svn -delete
findopen() { local PS3="select file: "; select file in $(find "$1" -iname "$2"); do ${3:-xdg-open} $file; break; done }
2010-02-28 02:28:59
User: quigybo
Functions: file find

lists the files found by find, waits for user input then uses xdg-open to open the selected file with the appropriate program.

usage: findopen path expression [command]

With the third optional input you can specify a command to use other than xdg-open, for example you could echo the filename to stdout then pipe it to another command.

To get it to work for files with spaces it gets a bit messier...

findopen() { files=( $(find "$1" -iname "$2" | tr ' ' '@') ); select file in "${files[@]//@/ }"; do ${3:-xdg-open} "$file"; break; done }

You can replace the @ with any character that probably wont be in a file name.

find ./ -name '*.sw[op]' -delete
find . -name "*~" -exec rm {} \;
2010-02-26 10:54:02
User: ivanatora
Functions: find rm
Tags: vim find

Assuming only VIM has *~ files in your current dir. If you have usefull data in a file named in the *~ pattern, DO NOT RUN this command!

find -type d -name ".svn" -print0 | xargs -0 rm -rf
2010-02-25 10:16:18
User: tuxilicious
Functions: find rm xargs

man find: If no paths are given, the current directory is used. - Can anybody tell me why so many people are typing the dot?

find . -iname "FILENAME" -exec sed -i 's/SEARCH_STRING/REPLACE_STRING/g' {} \;
2010-02-24 19:52:22
User: nanopino
Functions: find sed

using find's exec option instead of a for loop and using sed's -i option for inplace replacement. no need to do the file swap.

find /dev/vg00 -type b -exec lvextend -m 1 {} /dev/disk/<disk> \;
2010-02-24 18:41:33
User: Glip
Functions: find
Tags: hp-ux lvm

Mirror every lvol in vg00 in hp-ux 11.31