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
Related
I know this:
find . -perm -664
Search for files which have read and write permission for their owner and group,
and which other users can read.
but I can't figure out what is meaning of 04000 and 02000, maybe the lsattr could tell me? but I also have no idea about that.
THX.
I've come to the conclusion that both commands below give the same output:
SUID permission search command:
find / -perm -u=s -type f -ls 2>/dev/null
find / -perm -04000 -type f -ls 2>/dev/null
and also:
SGID permission search command:
find / -perm -g=s -type f -ls 2>/dev/null
find / -perm -02000 -type f -ls 2>/dev/null
Therefore find \( -perm -04000 -o -perm -02000 \) is searching for the permission bits of SUID and SGID. Documentation here: https://www.gnu.org/software/libc/manual/html_node/Permission-Bits.html
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
I have the next command to delete files which are large than 100KB:
find . -size +100k -delete
I want that it doesn't delete 3 files: a.html b.txt and c.html
How can I do it?
This should make it:
find . -size +100k ! -name "a.html" ! -name "b.html" ! -name "c.html" -delete
This should work:
find . -size +100k ! -regex "^\./[abc]\.html$" -delete
Add -maxdepth 1 is you want to perform deletion in current directory only.
Check out this page : http://www.cyberciti.biz/faq/find-command-exclude-ignore-files/
At the end, they say this:
Find all .dot files but ignore .htaccess file:
$ find . -type f \( -iname ".*" ! -iname ".htaccess" \)
This should do the trick for you, just substitude the -iname ".htaccess" for the name of your files :)
Hope it helps!
I want to find (recursively) writable files in my directory. My operating system is MacOS.
I tried:
find . -type -writable
but the shell returns an error:
find: -type: -writable: unknown type
Why I got the error? Are there alternatives?
Writable by whom?
If you mean writable by any, you can use:
find . -type f -perm -0222
or
find . -type f -perm -ugo=w
If you mean writable by other, use:
find . -type f -perm -0002
or
find . -type f -perm -o=w
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.