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

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.

Related

Fnd files that cannot be modified by others

I want my program to show me the files that can't be modified by others in the current directory. Here is what I have so far:
#!/bin/bash
find . -type f -perm u-w
I think you could use o-w permission for finding files not writable by others.
find . -type f -perm o-w

recursively find directories without setgid set

In linux, how do you recursively pull up a list of all directories that do NOT have the setgid bit set?
I know you can do
find . -type d /perm g+s
to find all the directories that have it set, but it's not obvious to me how to negate this. Or if another tool is more appropriate for this use case.
I've got a rather large directory tree and I'm trying to limit the operations I do on them.
You can simply add \! before an expression in find in order to negate it.
find . -type d \! -perm -g+s

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

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.

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).

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