[Slackbuilds-users] find/chmod revisited

Ricardo J. Barberis ricardo at palmtx.com.ar
Thu Nov 12 15:42:00 UTC 2015


El Jueves 12/11/2015, B Watson escribió:
> I've always known the template code that sanitizes the source permissions
> is a bit slow... for mame, it takes a full minute to execute (using tmpfs
> for TMP), since there are over 18 thousand files/dirs in the mame src.
>
> find -L . \
>  \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
>   -o -perm 511 \) -exec chmod 755 {} \; -o \
>  \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
>   -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \;
>
> ...executes one chmod process for each file/dir it finds. For mame:
>
> $ find /tmp/mame-mame0167/|wc -l
> 18664
>
> That's a lot of child processes! So I thought "maybe I can use xargs
> and cut the time down some". Result is this:
>
> find -L . \
>  \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \
>   -o -perm 511 \) -print0 | \
>   xargs -0 chmod 755
> find -L . \
>  \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \
>   -o -perm 440 -o -perm 400 \) -print0 | \
>   xargs -0 chmod 644
>
> ...which (on tmpfs) executes so fast I can't measure it accurately.
>
> Maybe the template code could be updated? mame isn't the only build
> that is affected by this. Anything with lots of files will be noticeably
> faster with this change.

And if xargs is not desired, find (at least on Slackware 14.1) 
suports '-exec ... {} \+'.

Also, find supports -executable, maybe those commands could be replaced by 
something like this?:

find -L . -executable -exec chmod 755 {} \+
find -L . -not -executable -exec chmod 644 {} \+


Not tested, and maybe should be checked against older versions of Slackware if 
appropriate.


Relevant sections of 'man find':

-exec command {} +
    This variant of the -exec action runs the specified command on the
    selected files, but the command line is built by appending each selected
    file name at the end; the total number of invocations of the command will
    be much less than the number of matched files. The command line is built
    in much the same way that xargs builds its command lines.
    Only one instance of `{}' is allowed within the command.
    The command is executed in the starting directory.

-executable
    Matches files which are executable and directories which are searchable
    (in a file name resolution sense). This takes into account access control
    lists and other permissions artefacts which the -perm test ignores. This
    test makes use of the access(2) system call, and so can be fooled by NFS
    servers which do UID mapping (or root-squashing), since many systems
    implement access(2) in the client's kernel and so cannot make use of the
    UID mapping information held on the server. Because this test is based
    only on the result of the access(2) system call, there is no guarantee
    that a file for which this test succeeds can actually be executed.


Cheers,
-- 
Ricardo J. Barberis
Usuario Linux Nº 250625: http://counter.li.org/
Usuario LFS Nº 5121: http://www.linuxfromscratch.org/
Senior SysAdmin / IT Architect - www.DonWeb.com


More information about the SlackBuilds-users mailing list