1819682 Members
3764 Online
109605 Solutions
New Discussion юеВ

find -perm

 
Scott J. Showalter
Frequent Advisor

find -perm

I am trying to figure out how to use the find command with the -perm option to find all files where the owner has read permissions but not wtrite and execute. So it should find files that match r--******

I tried:
find . -perm -u=r -exec ll -d {} \;

but that returned files with rw-rw---- also.

Any idea how to limit the find to just finding files with read only permissions?
In a world without fences, who needs Gates?
15 REPLIES 15
Marvin Strong
Honored Contributor

Re: find -perm

find . -perm 0400
Joseph C. Denman
Honored Contributor

Re: find -perm

Your command is fine except for the - in front of the u.

find ./ -perm u=r -exec ll -d {}\;


...jcd...
If I had only read the instructions first??
Marvin Strong
Honored Contributor

Re: find -perm

opps sorry read that too fast. thats not what you want ;p
Scott J. Showalter
Frequent Advisor

Re: find -perm

I tried that already:
find . -perm u=r -exec ll -d {} \;
That doesn't return anything.
I have a bunch of files that are
r--r-----
or
r--------
or
r--r--r--

and it doesn't find them.
In a world without fences, who needs Gates?
Scott J. Showalter
Frequent Advisor

Re: find -perm

Sorry, it does find ones that are r-------- but not r--r----- or r--r--r--
In a world without fences, who needs Gates?
Joseph C. Denman
Honored Contributor

Re: find -perm

you need to remove the -d option. Directories will always have the x perm.

# ll
total 52
-rwx------ 1 pmofabxx sa 814 Sep 2 2004 .cshrc
-r-------- 1 pmofabxx sa 347 Sep 2 2004 .exrc
-rwx------ 1 pmofabxx sa 341 Sep 2 2004 .login
-rw------- 1 pmofabxx sa 74 Jul 11 12:13 .ltime
-rwx------ 1 pmofabxx sa 6398 Sep 2 2004 .profile
-r-------- 1 pmofabxx sa 446 Sep 2 2004 .profile.old
-rw------- 1 pmofabxx sa 3424 Jul 11 12:14 .sh_history
drwx------ 2 pmofabxx sa 96 Aug 16 2005 .ssh
drwx------ 5 pmofabxx sa 96 Jun 13 15:40 .sw
drwxrwxrwx 4 root dba 2048 Jun 13 17:55 EWCF
drwxrwxrwx 3 root dba 2048 Jun 13 17:55 FDE-
# find ./ -perm u=r -exec ll {} \;
-r-------- 1 pmofabxx sa 347 Sep 2 2004 ./.exrc
-r-------- 1 pmofabxx sa 446 Sep 2 2004 ./.profile.old
#

...jcd...
If I had only read the instructions first??
A. Clay Stephenson
Acclaimed Contributor

Re: find -perm

Well it ain't pretty but:

find . -type f \( -perm -004 -o -perm -044 -o -perm -444 -o -perm -040 -o -perm -440 -o -perm -400 -o -perm -404 \) -exec ls -l {} \;
If it ain't broke, I can fix that.
Marvin Strong
Honored Contributor

Re: find -perm

not the best way probably but.

for g in 0 1 2 3 4 5 6 7
do
for o in 0 1 2 3 4 5 6 7
do
find . -perm 04${g}${o} -exec ll {} \;
done
done
Scott J. Showalter
Frequent Advisor

Re: find -perm

jcd - the ll -d is to prevent the ll from showing the files within directories. It shouldn't make a difference as to what I am trying to do.

acs - your solution while not pretty might work, but there would be a whole lot more possible combinations to cover all of the possibilities.

ms - your solution would also work, but way to many find commands running to be a viable solution.

I was hoping that I just misunderstood the man page, and it could be done with one command.
In a world without fences, who needs Gates?
A. Clay Stephenson
Acclaimed Contributor

Re: find -perm

No, those are all the permuatations of the READ bits, -perm 444 will only find files
that have exactly r--r--r-- mode set BUT -perm -444 (note the "-") will match rXXrXXrXX where X is "don't care".
If it ain't broke, I can fix that.
Marvin Strong
Honored Contributor

Re: find -perm

well you could use the for loops to create a single command, that you could run with all the -perm combinations.
Scott J. Showalter
Frequent Advisor

Re: find -perm

Clay,

Sorry for my mistake. But, I still have a problem, I do care about the rXX for the owner. I want it to find:
r--XXXXXX

but not any of the following:
rw-XXXXXX
r-xXXXXXX
rwxXXXXXX
In a world without fences, who needs Gates?
Marvin Strong
Honored Contributor

Re: find -perm

just another note in the for loops I am only running 1 find command at a time. not all 64 that it would have to process. But yes not ideal. Attached is a file you can use that will do what you want.


D Block 2
Respected Contributor

Re: find -perm


find . -type f -exec ls -l {} \;

this should list all the files and Modes..

then simply Piple the output into GREP for the pattern (or Regular Expression) you so desire/want.

play with the "ll" command in a small sized directory:
cd small_directory
ll | grep " r[rxw-]"

use the grep following the above find command in a pipe:
find .... | grep ....

remember: UNIX tools are KISS (Keep It Small and Simple) and use "pipe"..

have fun.


Golf is a Good Walk Spoiled, Mark Twain.
Peter Nikitka
Honored Contributor

Re: find -perm

Hi,

what about

find . ! -perm -200 -a ! -perm -500 | xargs ls -ld

mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"