But this way is more flexible as you can easily replace the = test with the =~ test and use it to check for more complex properties like executable plain text files or whatever other info your file command returns. 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. In Unix-like and some other operating systems, find is a command-line utility that locates files based on some user-specified criteria and either prints the pathname of each matched object or, if another action is requested, performs that action on each matched object. file-centric: find files that have (one or more) executable permission bits set. user-centric: find files that are executable by the current user.This answer attempts to provide an overview of the existing answers and to discuss their subtleties and relative merits as well as to provide background information, especially with respect to portability.įinding files that are executable can refer to two distinct use cases: Tip of the hat to gniourf_gniourf for clearing up a fundamental misconception.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |