What type of parameter/flag can I use with the Unix find
command so that I search executables?
相关问题
- JQ: Select when attribute value exists in a bash a
- Why should we check WIFEXITED after wait in order
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
相关文章
- Check if directory exists on remote machine with s
- Emacs/xterm color annoyance on Linux
- Making new files automatically executable?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
So as to have another possibility1 to find the files that are executable by the current user:
(the test command here is the one found in PATH, very likely
/usr/bin/test
, not the builtin).1 Only use this if the
-executable
flag offind
is not available! this is subtly different from the-perm +111
solution.does not really guarantee that the file is executable it will find files with the execution bit set. If you do
the above find will think image.jpg is an executable even if it is really a jpeg image with the execution bit set.
I generally work around the issue with this:
If you want the find to actually print dome information about executable files you can do something like this:
In the above example the file's full pathname is in the last field and must reflect where you look for it with awk "NAME=$(awk '{print $NF}' <<< $LINE)" if the file name was elsewhere in the find output string you need to replace "NF" with the correct numerical position. If your separator is not space you also need to tell awk what your separator is.
Well the easy answer would be: "your executable files are in the directories contained in your PATH variable" but that would not really find your executables and could miss a lot of executables anyway.
I don't know much about mac but I think "mdfind 'kMDItemContentType=public.unix-executable'" might miss stuff like interpreted scripts
If it's ok for you to find files with the executable bits set (regardless of whether they are actually executable) then it's fine to do
where supported the "-executable" option will make a further filter looking at acl and other permission artifacts but is technically not much different to "-pemr +111".
Maybe in the future find will support "-magic " and let you look explicitly for files with a specific magic id ... but then you would haveto specify to fine all the executable formats magic id.
I'm unaware of a technically correct easy way out on unix.