Having been a long time user of
find in unix, though I only recently stumbled into some of its more finer usages. Once example would be the usage of the
-exec
argument. I've spent countless hours piping find to a file, doing a global replace to execute the desired command and running it as a shell script; that I was simply thrilled to find that I could do it all in one single step :) (I only wish I had a little more patience reading the man pages that I would have stumbled into it sooner).
Take for example removing those pesky ws_ftp.log files that litter your directories when someone decides to use ws_ftp to ftp files instead of filezilla. Here is how you can get rid them in a single command
find . -type f -name 'WS_FTP.log' -exec rm -f {} \;
Another cool trick to get rid of the
Permission denied
messages that otherwise fill up the screen when doing global searches is to redirect stderr to
/dev/null
.
find / -type f -name 'serverindex.xml' -exec grep -l '8100' {} \; 2>/dev/null
One quick note about using
cygwin the
\;
that should terminate the exec portion of the find should actually be
\ ;
in cygwin or according to the wikipedia even a plain
;
will do