shell script to traverse files recursively
You should be looking at the find
command.
For example, to change permissions all JPEG files under your /tmp
directory:
find /tmp -name '*.jpg' -exec chmod 777 {} ';'
Although, if there are a lot of files, you can combine it with xargs
to batch them up, something like:
find /tmp -name '*.jpg' | xargs chmod 777
And, on implementations of find
and xargs
that support null-separation:
find /tmp -name '*.jpg' -print0 | xargs -0 chmod 777