chmod equivalent to find commands
Eric McCoy
emccoy at haystacks.org
Sat Mar 12 07:30:40 PST 2005
Fafa Diliha Romanova wrote:
> hello.
>
> i know there's an equivalent to these two find commands that
> can be summed up in one chmod command:
>
> find . -type d -exec chmod 755 {} \;
> find . -type f -exec chmod 644 {} \;
>
> it fixes my permissions ...
> i haven't tested this yet but i think it's wrong: chmod -R u+rwX,a+rX
>
> what would be the best solution here?
I would do it the same way you do, but with xargs instead:
find . -type X -print0 | xargs -0 chmod XXX
If you were feeling crazy and use sh:
find . | while read path; do \
if [ -d "$path" ]; then chmod 755;
else chmod 644; fi; \
done
The latter is overkill, but the approach can be useful for nontrivial
operations on systems that don't support -print0. It also has the
benefit that you can do it over ssh without having to copy over a
script, e.g.
ssh user at host sh -s <script.sh
(No nightmares from having to double- or triple-escape special
characters, either.)
Sorry, I don't know how to do it all with chmod. I assume you've
consulted the excellent FreeBSD man pages?
More information about the freebsd-questions
mailing list