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

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.

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

[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

Find by -name and -mtime, returns nothing

I am trying to use find command to delete some old file from backup folder but the find command return nothing, and so nothing is being removed! this is the code (find part), my system is ubuntu 18.04 LTS
find -name "*.sql" -type f -mtime +30
the result of find command
and the output of ls -l command is :
the result of ls -l command
I googled and searched the web but did find nothing to solve the problem. any help appreciated.
You are missing the starting point for your find command, in this case . because you already execute the command in the target directory:
find . -name "*.sql" -type f -mtime +30
the rest can stay the same.
First make sure it gives you the correct result and afterwards you can tack on the -exec to execute a command for each line of the result.
find . -name "*.sql" -type f -mtime +30 -exec rm '{}' ';'
You can usually find such answers on the UNIX stackexchange: How to execute ln on find results
Please see the comment from David in this particular case it might be a misunderstanding of the mtime parameter.
I have tested exactly the commands that were listed here, below you see
my preparation and some multiple usage, you can see how the files show up as expected, every time the mtime value decreases:
VIRTUAL BOX UBUNTU LTS 18.04
which is no surprise, given the man page of the find command:
FIND MAN PAGE / -mtime PARAMETER
please check for any typos... this should work.

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 files which do not have read permissions for other

I want to get all files which do not have read permissions for others.
I've tried find . -type f -perm -o-r and find . -type f -perm -o
But they return all files. Seems I'm doing something wrong.
Thanks.
Just search for anything that doesn't have the read permission for others:
find -not -perm -o=r
You can use:
find . -type f ! -perm -o+r

Resources