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

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

Related

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 to get all files and directories by user in Linux

I am trying to find all the directories and files owned by user with the following command.
find / -type d -user greg | grep -v proc
it is working fine sometimes and hanging up sometimes. Is there any performance issues associated with it or is there any better way to executing this.
To keep it from descending into /proc, use -prune. It's better than filtering out entries with grep -v as it'll avoid descending into /proc at all.
find / -path /proc -prune -o -type d -user greg -print
Read -o as "or". If the path is /proc, prune it, i.e. don't go in there. Otherwise, match directories owned by greg. (If you want files too then get rid of the -type d test.)
When you use -prune, you also have to use -print to print matches. -print's normally implied, but using -prune changes that.

how to list all directories for group has access to in unix/linux

Is there a way to list all directories for group has access to in unix/linux. Or a way to list all groups along with directories for which the group has access.
find all directories with execute permission (yes, execute as you need execute permission to a directory to be able to access files in it) that belong to group group.
find ${dir} -type d -group ${group} -perm -g=x -print
see man page of find(1) for details and examples of -perm option.
I believe that ls -lahp | grep '/' would do the job for you

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.

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.

Resources