Fnd files that cannot be modified by others - linux

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

Related

Find a file and export the full path to a list

I'm looking for a way to search certain files named "XYHello.pdf" or "BDHello.pdf" so basically "*Hello.pdf" in a directory with subfolder and export the found files including path to the file in a text file.
So that at the end I have a list with all found files including the paths in a list. I spontaneously thought about Linux Command find.
find . -type f -iname "*Hello.pdf"
But the problem is i need the full path to the file in a list.
find $PWD -type f -iname "*Hello.pdf"
or
find . -type f -iname "*Hello.pdf" -exec realpath {} \;

find files or directories that are 30 or more days old, recursively, BUT starting the search from specific directory

I have been searching but I cannot find a way to essentially do the following in 1 line at Linux, so as to find files and directories that are more than 30 days old, starting the recursive search from script_dir:
cd $script_dir
find . -type f -or -type d -mtime +30
If I do not do the cd to change to directory that I need to start searching from recursively (and use directly only the find), then, although I specify the script_dir at find the recursive search starts from the directory I am currently and NOT from the script_dir and beneath this directory. I want to do something like the following and even if I am currently at other directory than script_dir, the recursive search to start from script_dir:
find $script_dir -type f -or -type d -mtime +30
Thank you.
In one line, you can do like this :
cd /path/to/directory && find . -type f -or -type d -mtime +30
that do the search from the specified directory

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

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.

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