Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Mar 2005 10:30:46 -0500
From:      Eric McCoy <emccoy@haystacks.org>
To:        Fafa Diliha Romanova <fteg@london.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: chmod equivalent to find commands
Message-ID:  <42330B26.2040508@haystacks.org>
In-Reply-To: <20050312115359.C14EF4BE6D@ws1-1.us4.outblaze.com>
References:  <20050312115359.C14EF4BE6D@ws1-1.us4.outblaze.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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@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?



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?42330B26.2040508>