How do I find files/directories that are executable by anybody? - linux

I'm trying to find all files or directories that can be executed by EITHER user, group, or other. So far I have come up with this
find . -perm -u+x
I do not know how to search for group and other as well. I know that
find .-perm -ugo+x
will search for files/directories that can be executed by all 3 of those (essentially a+x).
I have searched and cannot figure out how to look for any of those 3. One place suggested
find . -perm -u+x, g+x, o+x
but i get the error
find: -perm: u+x,: illegal mode string
any ideas?

try this :
find . -perm /u=x,g=x,o=x

The POSIX-conformant syntax would be
find . \( -perm u=x -o -perm g=x -o -perm o=x \)
Each of the three -perm primaries checks if the file is executable by user, group, or other; they are joined by -o so that only one has to be true for the entire \(...\) group to be true.

Related

[linux find cmd]: limit the find command to search directories matching a given word or regex

Can I limit the find command to search directories matching a given regex only?
I looked at
$ man find
but couldn't find any --include-directories option.
Using RHEL GNU/Linux.
Thanks.
One way you can try is :
find . ! \( -name . -o -regex ".*/dir" \) -prune -name file
The problem for this solution is you have to include starting directory (. in this case)
-prune means to exclude all directories except . or .*/dir

How to find directories to which the owner and group has defined rights?

I would like search in a given tree directory directories to which the owner of the directory
(not necessarily the user executing the script) has the right to read, but do not have write or execute permission, and the owner group has the right to read.
what i have done so far:
find $1 -perm u+r -perm /u+wx ! -perm g+x
$1=provided argument to the script
This should work for you:
find $1 -type d ! -perm /u+wx -perm /u+r -perm /g+r
I think the reason your command wasn't working was because of the lack of a / in the last part - -perm g+x is telling find to match entries with exactly permissions 010. (Also, you said you wanted the group to be able to read, not execute).

Find all directories without r/x permissions for world/other

I want to find all the directories that that are not both readable and executable by the 'others'. Or put another way, anything where the permissions for 'other' users is anything except r-x or rwx.
I thought this woud work, but I'm off somehow:
find . -type d ! -perm -o+rw
This syntax will work:
find . -type d ! -perm /o+x,o+r
Check the examples section of the man page for more info.

how to exclude all subdirectories of a given directory in the search path of the find command in unix

I need to backup all the directory hierarchy of our servers, thus I need to list all the sub directories of some of the directories in the server.
The problem is that one of those sub directories contains tens of thousands of sub directories (file with only the names of the sub directories could take couple of hundreds megabytes and the respective find command takes very long).
For example, if I have a directory A and one sub directory A/a that contains tens of thousands of sub directories, I want to use the find command to list all the sub directories of A excluding all the sub directories of A/a but not excluding A/a itself.
I tried many variations of -prune using the answers in this question to no avail.
Is there a way to use the find command in UNIX to do this?
UPDATE:
the answer by #devnull worked very well, but now i have another problem, so i will refine my question a little:
i used the following command:
find /var/www -type d \( ! -wholename "/var/www/web-release-data/*" ! -wholename "/var/www/web-development-data/*" \)
the new problem that arises is that find for some reason is still traversing the whole directory tree of "/var/www/web-release-data/" and "/var/www/web-development-data/", thus it's very slow, and I fear it could take hours.
Is there any way make find completely exclude those directories and not traverse their respective directory hierarchies?
The following should work for you:
find A -type d \( ! -wholename "A/a/*" \)
This would list all subdirectories of A including A/a but excluding subdirectories of A/a.
Example:
$ mkdir -p A/{a..c}/{1..4}
$ find A -type d \( ! -wholename "A/a/*" \)
A
A/c
A/c/4
A/c/2
A/c/3
A/c/1
A/a
A/b
A/b/4
A/b/2
A/b/3
A/b/1
Another solution:
find A \! -path "A/a/*"
If you don't want a as well, use
find A \! -path "A/a/*" -a \! -path "A/a"
Have you tried rsync(1)? It has an option --exclude=PATTERN which might work well here:
rsync -avz --exclude=A/a <source> <target>
Using rsync you wouldn't need to use find(1)
To exclude 2 subdirs:
find . -type d ! -wholename "dir/name/*" -a ! -wholename "dir/name*"
To answer your updated question, you can do
find /var/www -wholename "/var/www/web-release-data/*" -o -wholename "/var/www/web-development-data/*" -prune -o -type d -print

Using `find -perm` to find when a permission is not set

I want to find the non-readable files in my directory (eg the files with g-r). So I tried this:
find . -perm -g-r
It shows me all of the files?? So I tried this:
find . -perm -g+r
And it showed me only the readable files. It appears that -perm -g-r matches all files. I'm using CentOS 5.5. Am I doing something wrong? It doesn't look like -perm -g-r does anything useful.
Try:
find . ! -perm -g+r
If you want to find files that are non-readable by you, you could use
find . ! -readable
on my Debian I need to escape the negation "exclamation mark"
so in your case it would be
find . \! -perm -g+r -ls
using numbers is also an option. This was my quest:
find . \! -perm /444
to see what really happens use:
find . \! -perm /444 -exec ls -la {} \;
You were able to see all files when you executed the below instruction, because you were executing it as root.
find . -perm -g-r
Try executing as a normal user.

Resources