[SATLUG] find

Daniel J. Givens daniel at rugmonster.org
Tue Apr 29 19:37:23 CDT 2008


travis+ml-satlug at subspacefield.org wrote:
> According to the find manpage:
> 
>        find . -perm /220
>        find . -perm /u+w,g+w
>        find . -perm /u=w,g=w
> 
>        All three of these commands do the same thing, but the first one uses the octal representation of the file mode, and  the
>        other  two  use the symbolic form.  These commands all search for files which are writable by either their owner or their
>        group.  The files don't have to be writable by both the owner and group to be matched; either will do.
> 
> Doesn't this seem wrong to anyone?
> 
> IMHO, it should work the same as chmod, which everyone is familiar
> with; namely, if you specify g+w, it means that group permissions
> contain at least write permission, and that g=w means that group
> permissions are exactly write (no group execute or group read).

You're forgetting the point of the / before the permissions. If you look 
in the manpage above the section you referenced for the -perm option, 
you'll see what I mean.

Executive Summary:
Using the following as an example:
-rw-r--r-- foo1
-rwxr-xr-x foo2
-rw-rw---- foo3

-perm <mode> : File's permission bits are exactly <mode>
	example:
	find . -perm 755
	matches foo2

-perm -<mode> : (At least) All of the permission bits mode are set for 
the file
	example:
	find . -perm -400
	matches foo1, foo2, foo3
	find . -perm -700
	matches foo2
	find . -perm -660
	matches foo1, foo3
	
-perm /<mode> : Any of the permission bits are set for the file
	example:
	find . -perm /777
	matches foo2
	find . -perm /444
	matches foo1, foo2, foo3
	find . -perm /060
	matches foo3

The last example is what your quote from the manpage applies to. find 
can certainly match permission patterns in the manner in which you're 
expecting it to, but sometimes, you want to find files where you only 
care about certain permissions and not others.

Hope this clears things up. I would be more than happy to explain further.

Regards,
Daniel


More information about the SATLUG mailing list