Moin,
Quote:
Originally Posted by Admiral Beotch
find /specified/dir * -exec commandToRunOnEachFileFound {} \;
|
No, this doesn't work correctly, because the unescaped asterisk is substituted with all pathnames in the current directory by the shell before find runs. BTW: To get all pathnames in a directory recursively you don't have to add a pattern,
find /specified/dir -exec commandToRunOnEachFileFound {} \; will work.
There are some ways, for example:
Code:
find /specified/dir -type f -print | while read f; do
TMP_FILE=`mktemp` || exit 1
do_something $f >$TMP_FILE && mv $TMP_FILE $f
done
find searches for all regular files in /specified/dir recursively, these file names are read by the loop, mktemp creates a temporary file with a unique name, then do_something is called for each file, the output is written to the temp file, on success the temp file is moved to the original file.
Code:
find /specified/dir -type f -print | xargs do_something
In this case do_something gets a bunch of pathnames as command line parameters and can process them in a loop. This way does not create a new process for each file.
Jan