LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-03-2015, 01:28 PM   #1
Simon_zhu
LQ Newbie
 
Registered: Jun 2015
Posts: 8

Rep: Reputation: Disabled
find command -perm options


I've been playing around with the -perm option of the find command, and I want to know what the difference is between the -perm -mode and -perm /mode
And if possible to give an example of each? I have tried both and they both seem to give the same result.
 
Old 07-03-2015, 03:19 PM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by Simon_zhu View Post
I've been playing around with the -perm option of the find command, and I want to know what the difference is between the -perm -mode and -perm /mode
And if possible to give an example of each? I have tried both and they both seem to give the same result.
If you look in the manpage, it describes how the mode is being used:
Code:
-perm -mode
              All of the permission bits mode are set for the file.   Symbolic
              modes  are accepted in this form, and this is usually the way in
              which would want to use them.  You must specify `u', `g' or  `o'
              if  you use a symbolic mode.   See the EXAMPLES section for some
              illustrative examples.
-perm /mode
              Any of the permission bits mode are set for the file.   Symbolic
              modes  are  accepted in this form.  You must specify `u', `g' or
              `o' if you use a symbolic mode.  See the  EXAMPLES  section  for
              some  illustrative  examples.  If no permission bits in mode are
              set, this test matches any file (the idea here is to be  consis‐
              tent with the behaviour of -perm -000).
-perm +mode
              This  is  no  longer  supported  (and  has been deprecated since
              2005).  Use -perm /mode instead.
And the examples section:
Code:
find / \( -perm -4000 -fprintf /root/suid.txt '%#m %u %p\n' \) , \
       \( -size +100M -fprintf /root/big.txt '%-10s %p\n' \)
ANY setuid file...(the only bit set - all other bits, since they are 0, are ignored). If any other bits are set, then the mode of the file must match ALL of them.

The major difference between the three (-/ and no prefix) is "ALL set bits must match, ANY set bit must match, and exact match"

and more examples from the manpage:
Code:
find . -perm 664

       Search for files which have read and write permission for their  owner,
       and  group,  but  which  other  users can read but not write to.  Files
       which meet these criteria but have  other  permissions  bits  set  (for
       example if someone can execute the file) will not be matched.

find . -perm -664

       Search  for  files which have read and write permission for their owner
       and group, and which other users can read, without regard to the  pres‐
       ence  of  any  extra  permission bits (for example the executable bit).
       This will match a file which has mode 0777, for example.

find . -perm /222
find . -perm -g+w,u+w

       Both  these  commands  do  the  same  thing; search for files which are
       writable by both their owner and their group.

find . -perm -444 -perm /222 ! -perm /111
find . -perm -a+r -perm /a+w ! -perm /a+x

       These two commands both search for files that are readable  for  every‐
       body  (  -perm  -444  or -perm -a+r), have at least one write bit set (
       -perm /222 or -perm /a+w) but are not executable for anybody ( !  -perm
       /111 and ! -perm /a+x respectively).
 
1 members found this post helpful.
Old 07-03-2015, 07:53 PM   #3
vincix
Member
 
Registered: Feb 2011
Distribution: Centos 6.7, 7
Posts: 556

Rep: Reputation: 52
Thank you. Very useful post. I was wondering how one can match any bit.
 
  


Reply

Tags
bash, find command, permissions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Linux find command -perm mode confusion diamond_D Linux - Newbie 2 03-05-2012 08:59 PM
help with find command (specifically the -o and -exec options) Bez Vozvrata Linux - General 3 06-06-2010 04:46 PM
find -perm the_imax Linux - General 2 12-05-2007 03:57 PM
vfat mount options (perm masks) shakezilla Slackware 7 09-22-2005 05:57 AM
find / \( -perm -0200 -o -perm -04000 \) -ls. How to remove the bit ForumKid Linux - Security 3 01-16-2002 12:36 PM


All times are GMT -5. The time now is 01:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration