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 tagged find from sorted by
Terminal - Commands tagged find - 350 results
find-duplicates () { find "$@" -not -empty -type f -printf "%s\0" | sort -rnz | uniq -dz | xargs -0 -I{} -n1 find "$@" -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all-repeated=separate; }
2013-01-23 23:20:26
User: mpeschke
Functions: find md5sum sort uniq xargs
-1

This is a modified version of the OP, wrapped into a bash function.

This version handles newlines and other whitespace correctly, the original has problems with the thankfully rare case of newlines in the file names.

It also allows checking an arbitrary number of directories against each other, which is nice when the directories that you think might have duplicates don't have a convenient common ancestor directory.

Find files that have been changed by a Chef run today.
find . -name "*.pdf" -exec pdftk {} dump_data output \; | grep NumberOfPages | awk '{s+=$2} END {print s}'
find . -type l -exec test ! -e {} \; -delete
2012-12-26 06:27:13
User: seb1245
Functions: find test
Tags: find
2

This command is adapted from http://otomaton.wordpress.com/2012/12/26/find-broken-symbolic-links/

Solutions with

find -L

don't work when the link is a loop, an error message is printed.

replace old new -- `find -type f`
2012-12-13 20:22:17
User: brian
Tags: sed find
1

Search and replace recursively. :-) Shorter and simpler than the others. And allows more terms:

replace old new [old new ...] -- `find -type f`

diff <(cd dir1 && find . | sort) <(cd dir2 && find . | sort)
find . -name "*.[ch]" -exec grep -i /dev/null "search pharse" {} \;
2012-12-04 20:51:04
User: MikeGoerling
Functions: find grep
Tags: find grep
0

Old Sys5 system and SUN computers don't have the -H option. Adding /dev/null forces grep to use the multi-file output and report the file name.

find . -type f -print | awk -F'.' '{print $NF}' | sort | uniq -c
grep -lir 'aMethodName' * | grep -v 'target'
2012-10-15 12:50:21
User: hay
Functions: grep
0

Finds all files recursively from your working directory, matching 'aMethodName', except if 'target' is in that file's path.

Handy for finding text without matching all your files in target or subversion directories.

find /path/to/search -xtype l
find . -name '*.rar' -execdir unrar e {} \;
2012-09-27 02:27:03
User: kyle0r
Functions: find
7

From the cwd, recursively find all rar files, extracting each rar into the directory where it was found, rather than cwd.

A nice time saver if you've used wget or similar to mirror something, where each sub dir contains an rar archive.

Its likely this can be tuned to work with multi-part archives where all parts use ambiguous .rar extensions but I didn't test this. Perhaps unrar would handle this gracefully anyway?

echo $(find <directory> -name '*.<extension>' -exec du -s {} \; | tee $(tty) | cut -f1 | tr '\n' '+') 0 | bc
2012-09-17 22:46:50
User: ysangkok
Functions: cut du echo find tee tr
-1

Also shows files as they are found. Only works from a tty.

find . -cnewer <file a> -and ! -cnewer <file b>
2012-08-15 21:57:42
User: rdc
Functions: find
Tags: find
1

This command finds all the files whose status has changed between the ctime of the older and newer .

Very useful if you can see from an ls listing a block of consecutive files you want to move or delete, but can't figure out exactly the time range by date.

ff() { find -maxdepth 3 -type f -iname "$1"; }; fd() { find -maxdepth 4 -type d -iname "$1"; }
2012-08-15 15:04:48
User: plasticboy
Functions: find
Tags: find simple
-1

These should be a little faster since they don't have to spawn grep.

ff() { find -maxdepth 3 -type f | grep -i "$1"; }; fd() { find -maxdepth 4 -type d | grep -i "$1"; }
find . -type f -exec ls -l --full-time {} + | sort -k 6,7
2012-08-03 22:22:51
User: quadcore
Functions: find ls sort
Tags: sort find ls
2

This sorts files in multiple directories by their modification date. Note that sorting is done at the end using "sort", instead of using the "-ltr" options to "ls". This ensures correct results when sorting a large number of files, in which case "find" will call "ls" multiple times.

find . -type f -exec du -sh {} + | sort -hr | head
find /backup/directory -name "FILENAME_*" -mtime +15 -exec rm -vf {} +
find . -type f -exec ls -shS {} + | head -10
2012-07-28 17:21:46
User: erichamion
Functions: find head ls
0

This requires a version of GNU find that supports the -exec {} + action, but it seems more straightforward than the versions already posted.

find . -type f \( -name '*.c' -o -name '*.cpp' -o -name '*.cc' -o -name '*.cxx' \) | xargs grep "#include.*\.c.*" 2>&1 | tee source_inside_source_list.txt
sudo find / \( -nouser -o -nogroup \)
2012-07-13 07:09:08
User: gwd
Functions: find sudo
1

suspicious/anomalous ownership may indicate system breach; should return no results

sudo find / -perm -2 ! -type l -ls
find . -type f -print0 | xargs -0 du -h | sort -hr | head -10
find . -type f -print0 | xargs -0 du -h | sort -hr | head