![]() ![]() Though if you are on OS X it comes with a little utility hidden somewhere called is_exec that basically bundles up that little test for you so you can shorten the command line if you find it. Gniourf_gniourf's answer provides a true, portable equivalent of -executable, using -exec test -x '") = *" executable "* ]] ' \ -print As a bonus, it also happens to be POSIX-compliant (use find -L to include symlinks, see farther below for an explanation): find. Perhaps a closer approximation than -perm +111 is -perm -111, so as to find files that have the executable bit set for ALL security principals (user, group, other) - this strikes me as the typical real-world scenario. Thus, the best -perm can do (by itself) is an approximation of -executable. ![]() Using only POSIX find features, the question cannot be answered without involving external utilities. Using just -perm to answer the user-centric question is impossible, because what is needed is to relate the file's user and group identity to the current user's, whereas -perm can only test the file's permissions.The BSD find alternative offered by the accepted answer ( -perm +111) answers a different, file-centric question (as the answer itself states). As the scenario demands, -executable matches only files the current user can execute (there are edge cases.By contrast, BSD-based platforms, including macOS, come with BSD find, which is less powerful.The accepted answer commendably recommends -executable, IF GNU find is available. Note that the simplest file-centric case - looking for executables with the executable permissions bit set for ALL three security principals (user, group, other) - will typically, but not necessarily yield the same results as the user-centric scenario - and it's important to understand the difference. in order to also find symlinks to executables. ![]() Note that in either scenario it may make sense to use find -L.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |