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,039 results
find * -type d -exec mkdir /where/you/wantem/\{\} \;
find . -name "*.php" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o ../newdir_utf8/{} \;
find <dir> -type f -mtime +<days> -exec scp -r {} user@backuphost:/data/bkup \;
2009-02-12 07:43:29
User: rbattu
Functions: find scp
-1

U have to make key exchange in order to avoid continuous password prompt.

i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done
find ./* -name 'CVS' | awk '{print "dos2unix " $1 "/*"}' | awk '{system($0)}'
find . -name Root -print | xargs rm -f
find . -name "*.java" -exec gnome-terminal \-x vim {} \;
2009-02-10 09:38:04
User: root
Functions: find vim
-6

Not that useful really, more novel. Can open up an awful lot of terminal windows.

find . -name "*.php" -exec php -l {} \; | sed -e "/^No syntax/d"
2009-02-10 09:14:25
User: TomNomNom
Functions: find sed
1

Uses the PHP binary to check the syntax of all .php files in or below the current working directory. Really handy for doing that last minute check before you commit code to the repository.

find /dir/ -name *name*
2009-02-09 20:24:10
User: cinan
Functions: find
-5

"*" is important if you don't know exact name of file. Check it out and you'll see

find . \( -name '*.h' -o -name '*.cc' \) | xargs grep . | wc -l
2009-02-09 11:44:35
User: dgomes
Functions: find grep wc xargs
3

Counts number of lines of code in *.h and *.cc files

find ~/random_jpegs/folder -name "*.jpg" -exec rdjpgcom {} \;
2009-02-09 02:58:13
User: Williebee
Functions: find
0

depends on libjpeg-progs

But how to display path to found comments?

find /path -name \*.php -user nobody -exec grep -nH whatever {} \;
2009-02-07 20:53:56
User: al3x
Functions: find grep
0

allows to grep very narrow subset of files

find /path -type d -perm 777 -exec chmod 755 {} \;
find $(pwd) -type f -exec grep -l "$(echo "\r")" {} \;
2009-02-07 18:53:00
User: mnikhil
Functions: find grep
1

its useful to run dos2unix command later on them.

find ./source -depth -print | cpio -cvo> /destination/source_data.cpio; cd /destination; cpio -icvmdI ./source_data.cpio; rm -rf ./source_data.cpio
2009-02-07 18:51:49
User: mnikhil
Functions: cd cpio find rm
0

Copy data to the destination using commands such as cpio (recommended), tar, rsync, ufsdump, or ufsrestore.

Example:

Let the source directory be /source, and let the destination directory be /destination.

# cd /source

# cd ..

# find ./source -depth -print | cpio -cvo> /destination/source_data.cpio

# cd /destination

# cpio -icvmdI ./source_data.cpio

# rm -rf ./source_data.cpio

find / -xdev -size +1024 -exec ls -al {} \; | sort -r -k 5
find . -name "*.jpg" | perl -ne'chomp; $name = $_; $quote = chr(39); s/[$quote\\!]/_/ ; print "mv \"$name\" \"$_\"\n"'
find ~ -name '*.sqlite' -exec sqlite3 '{}' 'VACUUM;' \;
2009-02-07 10:45:41
User: ggyy_sun
Functions: find
24

Compress information DBs of firefox to speed up the launch of browser.

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