in reply to Limitations to chmod and performance

You might consider system 'find'.

$ find /the/dir -name \*.dat -not -perm 644 -exec chmod 644 \{\} \;
find2perl can translate such a command to pure perl, but it doesn't understand +signed notation for the -perm any-bit argument (version dated 1998/04/07, easy to fix that).

Whatever solution you use, you can prune statting all regular files in a dir whose mtime is prior to the last run. chmod acts on the inode, not the file, so the directory times are what counts.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Limitations to chmod and performance
by stefan k (Curate) on Nov 12, 2001 at 21:04 UTC
    Actually such a script is replaced. And I wouldn't know how to elegantly and efficiently have a list with exceptions put in that code. But thanks anyway (the hint with mtime and last run is a good one (just like the prior postings contained good hints - thank you, Monks! :)

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

Re: Re: Limitations to chmod and performance
by stefp (Vicar) on Nov 13, 2001 at 06:59 UTC
    Using the command find instead of File::Find is not a bad thing per se. But as you do it, you will fork a chmod command per matching file. Since you are concerned by performance issue, let us say it may be better to optimize by bundling as much files as possible in an exec command by using xargs:

    find /the/dir -name \*.dat -not -perm 644 | xargs chmod 644

    To be on the safe side and to deal correctly with weird file names (like windoze filenames with blanks), it is even better to use the null character as a file separator:

    find /the/dir -name \*.dat -not -perm 644 -print0 | xargs -0 chmod 644

    -- stefp