Run a UNIX command on each file in a directroy 

http://h3g3m0n.wordpress.com/2007/03/28/run-a-unix-command-on-each-file-in-a-directroy/

First there is the basic for loop, it is able to handle files with spaces in the filename, e.g., it works for files like "Sample File.txt".

for file in *; do echo "Updating timestamp for $file"; touch "$file"; done

Using find with xargs, this only seems to be able to handle one command at a time (unless you bother to write a script for it). It puts all the commands on one line, rather than executing the command multiple times. It also doesn't support more than one command, so echoing the message for each individual file seems impossible and it won't work on commands unless they accept multiple filenames.

find . -print0 | xargs -0 touch

The next one is to use find with the -exec argument and some odd parameters, this allows for multiple command and spaces :):

find . -exec echo "Updating timestamp for" {} \&\& touch {} \;

Finally if you want something thats a bit nicer for use in scripts you can use read to stop the splitting of filenames:

find . | while read FILE; do
echo "Updating timestamp for $FILE"
touch "$FILE"
done;