dmiessler.com — find is one of the most useful Linux/Unix tools around, but most people use only a fraction of its power. Many Linux/Unix questions seen online can be solved using the find command alone; it's simply a matter of becoming familiar with its options...
Oct 10, 2006 View in Crawl 4
Closed AccountOct 11, 2006
rm -rf /your mom
Closed AccountOct 11, 2006
Not when you are operating on, say, 100 thousand files.
widmanOct 11, 2006
The title is wrong. The find utility is not Linux, it's AT&T UNIX, with BSD and GNU clones. Linux is a kernel with some programs.And it abuses using xargs instead of -exec. Of course it's not the same and xargs can be useful if you need to process the output first.
edlesmannOct 11, 2006
"Correct me if I?m wrong, but doesn't -exec also run the command immediately when it finds a match? And by piping doesn't it not run the pipe until after everything is found? "You are correct. If I were to find all the files in the directory, and grab their md5sum I would do it like:find . -type f -exec md5sum {} ;and I would get something likefebe6995bad457991331348f7b9c85fa ./1c193497a1a06b2c72230e6146ff47080 ./2If I were to do it the other wayfind . -type f | md5sumI would only get1d71cf268d99994d0168f1f18dab3337 -which is not what I wanted at all.Of course, you may want it backwards. Doing a find . -type f -exec uniq {} ; does a uniq on the _contents_ of the files, not on the files themselves. if you wanted to sort the files, you would have to do find . -type f | uniq.Hope that helps clarify....
greyfadeOct 11, 2006
the article's argument against -exec is very weak, IMO. true, it does incur the overhead of loading and executing the command repeatedly, but -exec allows you to craft very complex commands based on rules - something xargs doesn't do. all xargs does is iterate over a list and pass them as arguments to a command. it's not terribly flexible in that regard.(i also didn't see mention of the fact that -print0 is used with xargs to work around quoting problems for complex filenames. -print works fine if none of the filenames need special quoting.)@edlesman: the second command doesn't do what you want because you're taking the md5sum of a /list/ of files. not the files themselves. "find -type f -print0 | xargs -0 md5sum" would do exactly what you want and spqwn only a handful of processes doing it.
edlesmannOct 11, 2006
@greyfadeI agree. I was just trying to emphasis the previous point that the | and the -exec dont necissarily do the same thing as the order they are performed in impacts the outcome.BTW just for grins, I ran my example on a folder of 2.1gigs of data and then I ran the xargs example on the same folder. The xargs was 4 seconds faster. I am most certainly going to start using this more often :-D
itchybeardOct 16, 2006
ruby -e 'print Dir["/usr/local/**/*"].join(0.chr)' | xargs -0 ls -ld