Hide

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.

Hide

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:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands using find from sorted by
Terminal - Commands using find - 1,021 results
find ~ -name '*.mp4' | xargs mplayer
find . -exec grep "test" '{}' /dev/null \; -print
find . -name "*~" -exec rm {} \;
find DIR -name "FILE" -exec grep -IHn STRING {} \;
find . -name "*.txt" | xargs perl -pi -e 's/old/new/g'
2009-02-06 00:28:03
User: neztach
Functions: find perl xargs
6

syntax follows regular command line expression.

example: let's say you have a directory (with subdirs) that has say 4000 .php files.

All of these files were made via script, but uh-oh, there was a typo!

if the typo is "let's go jome!" but you meant it to say "let's go home!"

find . -name "*.php" | xargs perl -pi -e "s/let\'s\ go\ jome\!/let\'s\ go\ home\!/g"

all better :)

multiline: find . -name "*.php" | xargs perl -p0777i -e 's/knownline1\nknownline2/replaced/m'

indescriminate line replace: find ./ -name '*.php' | xargs perl -pi -e 's/\".*$\"/\new\ line\ content/g'

find $PWD -exec rpm --query -f {} \; | sort -u | grep -v "not owned"
2009-02-05 19:33:43
User: wwest4
Functions: find grep rpm sort
0

shows all RPMs with files in the current directory & its subdirectories.

find /path/to/dir -type f -mtime +[#] -exec rm -f {} \;
2009-02-05 19:24:13
User: wwest4
Functions: find rm
1

deletes logs not modified in over [#] days - modify to compress or move, as needed

find . -type d -name '.svn' -print0 | xargs -0 rm -rdf
find . -name "*.py" | xargs wc -l
ct find -avobs -nxname -element 'brtype(branch_name)' -print 2>/dev/null
chgrp -R [projgroup] ; find /path/to/dir -type d -exec chmod g+s {} \;
2009-02-05 16:49:24
User: wwest4
Functions: chgrp chmod find
0

changes group ownership of all files/dirs in /path/to/dir to a project group [projgroup] and then gives the sgid bit to directories in that tree - all subsequently created files will inherit [projgroup]'s gid.

find /path/to/dir -user root -exec chown [nonprivuser] {} \;
2009-02-05 16:42:14
User: wwest4
Functions: chown find
0

useful if you want to start running a svc as a non-privileged user instead of root.

find . -regex ".*\.[cChH]\(pp\)?" -print | etags -
2009-02-05 16:27:26
User: chidarste
Functions: etags find
0

The regular expression matches patterns of .c, .cpp, .C, .Cpp, .h, .hpp, .H, .Hpp. The matched files are piped through etags to create a TAGS file, useful for emacs. Alternate regex (if you aren't worried about capital .Cpp) is -regex ".*\.c\|.*\.cpp\|.*\.h"

find /path/to/dir -type f |sed 's/^.*\///'|grep -o '\.[^.]*$'|sort -f|uniq -i
find . -type f -print0 | grep -vzZ '.svn' | xargs -0 grep --color -nEHi "SEARCHTERM"
2009-02-05 10:27:15
User: troelskn
Functions: find grep xargs
-3

Variant of find grep that ignores files with .svn in the name. Useful for searching through a local repository of source code.

URL=www.example.com && wget -rq --spider --force-html "http://$URL" && find $URL -type d > url-list.txt && rm -rf $URL
2009-01-27 17:59:08
User: root
Functions: find rm wget
1

This spiders the given site without downloading the HTML content. The resulting directory structure is then parsed to output a list of the URLs to url-list.txt. Note that this can take a long time to run and you make want to throttle the spidering so as to play nicely.

find /path/to/dir -type f -exec grep \-H "search term" {} \;
2009-01-26 16:32:14
User: root
Functions: find grep
-1

Simple use of find and grep to recursively search a directory for files that contain a certain term.

find /path/to/dir -type f -print0 | xargs -0 rm
2009-01-26 11:30:47
User: root
Functions: find xargs
12

Using xargs is better than:

find /path/to/dir -type f -exec rm \-f {} \;

as the -exec switch uses a separate process for each remove. xargs splits the streamed files into more managable subsets so less processes are required.

find . -name "*.php" -exec grep \-H "new filter_" {} \;
2009-01-26 10:43:09
User: root
Functions: find grep
0

This greps all PHP files for a given classname and displays both the file and the usage.

find . \( -name "*.php" -o -name "*.js" \) -exec svn propset svn:keywords Id {} \;
find . -type f | wc -l