Quote:
Originally Posted by mnt_schred
I still don't get why the cat method wouldn't work though..
|
Redirections (">") are handled by the shell, so when you say
Code:
find . -name '*.jpg' -exec cat /dev/null > "{}" \;
The shell does this
Code:
# execute find with the following arguments
find . -name *.jpg -exec cat /dev/null ;
# with output redirected to a file called {}
The arguments between
-exec and
; are what
find executes; obviously
cat /dev/null produces nothing useful so you get an empty file called
{}.
To handle the redirection the way you want, you to quote it to protect from the outer shell, and tell
find to use a shell to interpret the quoted command:
Code:
find . -name '*.jpg' -exec /bin/bash -c "cat /dev/null > '{}'" \;
which means
Code:
# execute find with the following arguments
find . -name *.jpg -exec /bin/bash -c cat /dev/null > '{}' ;
Although, as you can see from
mddesai's suggestion,
cat and
/dev/null aren't strictly needed.