NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: Find all files with at least one execute bit set
Steffen Nurpmeso wrote in
<20250814212707.6XsmTpHW@steffen%sdaoden.eu>:
|RVP wrote in
| <4a495fb2-150d-67b7-cbbc-8a799868d595%SDF.ORG@localhost>:
||On Thu, 14 Aug 2025, Rocky Hotas wrote:
||
||> I'm trying to use find(1) in a POSIX way to list all the files (not
||> directories) with at least one execute bit set.
||> [...]
||> find /target_directory/ -type f -perm -001 -or -type f -perm -010 \
||> -or -type f -perm -100
||>
||> Is there a more compact, but still POSIX, way to obtain the same
||> result with NetBSD's find(1)?
||
||If not sticking to pure find(1):
||
||Compact, but slow, and filenames cannot contain (')--single quotes.
||
||$ find /dir/ -type f -exec sh -c "test -x '{}' && echo '{}'" \;
||
||Slightly faster, and should handle weird filenames:
||
||$ find /dir/ -type f -exec sh -c 'for f; do test -x "$f" && echo "$f"; \
||done' xxx {} +
||
||Note the `xxx' above. It, or some other string, is reqd. there to supply \
||a `$0'
||for the shell. Of course, you would usually put all this in a shell \
||script, then
||`-exec' that :).
|
|fwiw GNU find(1) has
|
| -perm /mode
| Any of the permission bits
| -perm -mode
| All of the permission bits
|
|which then is pretty cool
of course not POSIX as you have asked; but .. dependent upon the
task it might still be worth doing something like
find . -perm /0111 --help
or something, you know, and then go the one or other route?!
(And/or create a function which actually acts etc etc etc.)
Out of interest i just now looked, OpenBSD and NetBSD do not
support + or /, FreeBSD documents + but not /, busybox and GNU
find support + and /, but the former only documents + and the
latter obsoleted + in favour of /, but still supports it.
So lots of work all over the place!
||-RVP
| --End of <4a495fb2-150d-67b7-cbbc-8a799868d595%SDF.ORG@localhost>
--End of <20250814212707.6XsmTpHW@steffen%sdaoden.eu>
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
Home |
Main Index |
Thread Index |
Old Index