a quicker way to 'normalize' an entire directory tree with weird chmod-ed files than the classic shell way (
find . -type d -exec chmod 0755 {} \; find . -type f -exec chmod 0644 {} \;
)
#!/usr/bin/perl -w use strict; use File::Find; + find( { wanted => sub{ chmod((-f)?0644:0755,$_) if -d||-f } }, defined $ARGV[0] ? $ARGV[0] : '.' );

UPDATE: just had a privmsg discussion regarding this snippet and it looks that some people seem to be missing the point - goldclaw's reply is doing a DIFFERENT thing from my original goal. He somehow explained in his reply that files get chmod-ed to 0755 "if it has one or more execution bits allready set", but that's not my intention (i.e. remember Apache and XBitHack and you'll see why).
I really hope this update will clarify this missleading issue, as I see many users using chmod's X flag without perfectly understanding what's its functionality.

Replies are listed 'Best First'.
Re: 'pubify' directory tree
by goldclaw (Scribe) on Jan 28, 2001 at 04:07 UTC
    OK, your bringing out the chainsaw here.I know perl is great, but sometimes its overkill. This at least works with gnu chmod and probably most other UNIX OS:
    chmod -R go=rX,u=rwX <dirname> <dirname>

    The capital X turns on execution if its a directory, or if it has one or more execution bits allready set. The -R means that it changes permission recursively on all the directories its given.

    GoldClaw