[Slackbuilds-users] template find/chmod RFC
Yiannis
rizitis at gmail.com
Mon Aug 3 18:34:18 UTC 2026
One small thing before someday it becomes a template. As written:
find . ! -type l -a \
\( -perm /111 -a ! -perm 755 -a -exec chmod -f 755 {} + \) -o \
\( ! -perm /111 -a ! -perm 644 -a -exec chmod -f 644 {} + \)
-a binds tighter than -o, so this parses as
( ! -type l AND first-group ) OR ( second-group )
and the "! -type l" never applies to the second branch. It is still safe
on Linux, but incidentally rather than by design: the kernel forces mode
0777 on symlinks (umask is ignored, there is no lchmod, and even tar
cannot restore a different mode), so "! -perm /111" is false for them and
the 644 branch never fires. That is a property of Linux symlink modes,
not of the guard - and it stops being true on an NFS or FUSE mount from
a host where symlinks do carry real modes.
One outer group fixes it:
find . ! -type l -a \( \
\( -perm /111 -a ! -perm 755 -a -exec chmod -f 755 {} + \) -o \
\( ! -perm /111 -a ! -perm 644 -a -exec chmod -f 644 {} + \) \
\)
Same behaviour, same timing, two extra characters - but now the code stays
more correct if either branch
is ever edited.
Στις Δευ 3 Αυγ 2026 στις 8:52 μ.μ., ο/η Andrzej Telszewski <
andrzej at telszewski.com> έγραψε:
> On 03/08/2026 14:31, Franzen via SlackBuilds-users wrote:
> >
> >> chmod -R u+w,go-w,a+rX-st .
> >
> > Here is an explanation why my proposal might not be that good. It's 13
> > years old, maybe chmod has changed to the better:
> > https://unix.stackexchange.com/a/79874
>
> Unless enforced by SBo rules, I'll prefer `chmod -R` variant over `find`
> variant,
> for its compactness.
>
> Now, it's not strictly important how much time changing the permissions
> takes,
> but how much time does it take compared to the build time as a whole.
>
> --
> Best regards,
> Andrzej Telszewski
>
> _______________________________________________
> SlackBuilds-users mailing list
> SlackBuilds-users at slackbuilds.org
> https://lists.slackbuilds.org/mailman/listinfo/slackbuilds-users
> Archives - https://lists.slackbuilds.org/pipermail/slackbuilds-users/
> FAQ - https://slackbuilds.org/faq/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.slackbuilds.org/pipermail/slackbuilds-users/attachments/20260803/8dc7c6f3/attachment.htm>
More information about the SlackBuilds-users
mailing list