Thank You, GNU Find!

by chromatic

I just used GNU find to search a directory hierarchy for files matching a particular naming pattern. I've been programming for long enough that writing a tree-walking algorithm to search for appropriately-named leaves is almost trivial, but the point is that I don't have to do that. Piping the output of find into my filter program to search within the files was sufficient.

I use the other findutils programs--especially locate--several times each week. Without them, I'd get lost in a sea of thousands of files. Thank you to all of the developers and contributors. You saved me a few minutes today, as you do almost every day.


Wes Ratcliff
2007-03-26 16:29:17
I agree with you 100% - find and it's friends are lifesavers.

I posted up a few of the commands I use the most on my blog.

Got any other commands you use?

2007-03-26 19:32:11
Thank you sun for shining. I use you every day to help me see in the dark. I could run around and collect together 10^n tonnes of matter and create my own fusion reaction, but thanks to you, I don't have to do that.

Stay tuned for an impending paean to gravity - very useful for those morning trips to the toilet.

2007-03-26 21:24:11
@kinch, yes, it's an obvious utility for just about anyone who's spent any time at the command line, but I used it today and for the first time really thought about how convenient it is.

I've never really thanked all of the people who've contributed to software (code and otherwise) for the projects I use most often. I'm trying to do so. Their work enriches me daily.

2007-03-26 22:08:32
@chromatic, point taken and my apologies - just feeling a bit mean today... and am perhaps a teeny bit jaded by 'content free' blog postings which often exist for reasons other than to inform. I realise that this is not the case with you since this is your employer's site, but nonetheless you might run the risk of eliciting rather unfair knee-jerk reactions from the cynics among us (obviously people like me:). Just my POV.

Slightly off-topic, can you figure out why, when I am subscribed to the PythonDevCenter atom feed, I keep getting off-topic (it's a theme today) stuff from Looking at the web page URLs gives me an obvious hint... but it seems to me that if I wanted to know LAMP specific stuff, I'd go and subscribe to a LAMP specific feed. Similarly, the fact that I have subscribed to the PythonDevCentre *feed* suggests that I am interested in Python stuff and not extraneous 'noise'.

Call me narrow-minded and averse to new stuff, etc... (although that is not true)... it's more that one of the points of syndication is to permit this kind of specialisation. If I wanted to know the other stuff, I'd be browsing the page or subscribed to the top-level feed there.

2007-03-27 00:51:35
You're welcome.
jeremiah foster
2007-03-27 03:28:52
Yeah James, thanks! I use find a lot, although I am definitely an amateur when it comes to find. I have seen some nifty recipes piping it into xargs and have even tried a few but that is too many options for me to store in my little head. I love locate too, I always put updatedb in cron as one of the first acts on a new machine.
Paul Annesley
2007-03-27 05:32:27
Rather than piping to xargs, try finds -exec parameter.
For example, to delete all those damn mac resource forks...

find . -name '._*' -exec rm -f {} \;

Harald Hanche-Olsen
2007-03-27 11:44:27
-exec is good for fairly simple tasks, like removing files. But if you use xargs, better get in the habit of doing
find ... -print0 | xargs -0 ...
in order to avoid nasty surprises due to filenames with spaces or even newlines in them.

For doing complicated processing, I like the recipe
find ... -print0 | xargs -0 sh -c 'for x; do ...; done' -
(the trailing argument is needed because it becomes $0 in the shell, leaving room for the filenames to go in $*). (And in real life, I use a different shell. Same principle.)

Oh, and there is this one, for recursively removing empty directories:
find . -depth -type d -empty -exec rmdir {} \;

2007-03-27 14:32:34
@kinch, I agree that the feeds should be more specific; we're working on it.
2007-03-27 17:24:46
The Chinese proverb says: When you drink water, remember the mountain spring. A wise habit to adopt. We so take for granted the many kindesses of untold numbers of people every moment of our comfortable lives. For every bite we eat, for every convenience we enjoy, for every bit of fabulous code we use. I give thanks every time I fire up my emacs environment, include a CPAN module, and write a line of perl... I'm the beneficiary of genious, ... and it does not matter that I don't deserve it.
Matthew Sporleder
2007-03-29 11:30:11
A much simpler find command appeared in First Edition AT&T Unix. The syntax had become similar to the present version by the time of the Fifth Edition.