I want to write a permission fix script that uses find to fix permissions on files.
Mainly what I need is a find command that is able to list all files with execute bit set, regardless of the other permissions on the file (that's the trick).
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityOn GNU's find:
find /dir -type f -executable
On other versions, see the man page around -perm
.
Believe it or not this is extensively documented in the find man page. On the CentOS and Ubuntu systems I have to hand there are even examples of this.
-perm /mode
Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify
u',
g' or `o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with the behaviour of -perm -000).
So
find . -perm /u+x
will find files where execute permission is set for the owner
find . -perm /u+x,o+x
will find files where execute permission is set for the owner and other and so on.
Without using the find command, on zsh we can do something like this using Glob Qualifiers
:
ls /path/to/some/parent/folder/**/*(*)
The above ls
command will return all files in all subfolders of /path/to/some/parent/folder
, which are executable.
...
iyswim ;)