Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

used find command with -perm switch to find files where ugo does not have x execute permissions

Hi Guys,
Is it possible and how does on use the find command with -perm switch to find all files where neither the user, group or other has (x) execute permissions.


Cheers


B Cunney
0
Barry Cunney
Asked:
Barry Cunney
  • 12
  • 9
1 Solution
 
ozoCommented:
! -perm +111
! -perm +ugo+x
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
No that does not work - I understand what you are illuding to though
.... but I am trying to find all files where ugo does NOT have execute permissions


Cheers


 
0
 
Barry CunneyAuthor Commented:
I did the following test:
$ ls -l
-rwxrw-r-- 1 barry users 4 Oct 4 16:30 file1
-rw-rw-r-- 1 barry users 4 Oct 4 16:31 file2
-rw-rw-r-x 1 barry users 6 Oct 4 16:31 file3
$ find . -type f \! -perm -0111 -print
./file1
./file2
./file3
$ find . -type f ! -perm -0111 -print
./file1
./file2
./file3

As you can see all three files are returned no matter which way I type the find command

Only 'file2' should be returned because this is the only file where u+g+o do NOT have (x) execute permissions

I only want to find files where all three 'groups' do not have execute permissions.
I am not interested in whether all or any groups have read or write permissions - I am only interested in the (x) execute section for each group

Cheers
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
ozoCommented:
I think I said +111 not -111
0
 
Barry CunneyAuthor Commented:
H Ozo,
I tried this and it doesn't work:
$ find . -type f ! -perm +111 -print

Message returned:
UX:find: ERROR: bad permissions: +111


Cheers
0
 
ozoCommented:
What version of find/unix are you using?
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
Version of Unix: SCO Unix - Unixware 7.1.1

What is the best way to establish the version of find command I have?


Cheers
0
 
Barry CunneyAuthor Commented:
Ho Ozo,
The date of the 'find' file in bin directory is Oct 12 1999 and the size is 15484


Cheers
0
 
ozoCommented:
I do not have access to SCO Unix to test this, but try:
! \( -perm -1 -or -perm -10 -or -perm -100 \)
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
This is the return from that - I am just double-checking the syntax but I think I have it like you suggested

$ find . -type f !\(-perm -1 -or -perm -10 -or -perm -100\) -print
UX:find: ERROR: Illegal option -- !(-perm
UX:find: TO FIX: Usage: find [path-list] [predicate-list]
$


Cheers
0
 
ozoCommented:
Space between !  \( -perm and -100 \)
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
Again I  might  get you to check if I have syntax right
$ find . -type f ! \(-perm -1 -or -perm -10 -or -perm -100 \) -print
UX:find: ERROR: Illegal option -- (-perm
UX:find: TO FIX: Usage: find [path-list] [predicate-list]
$

Cheers
0
 
Barry CunneyAuthor Commented:
Hi Ozo
I put a space in after the first opening bracket in case this was affecting anything - result below
$ find . ! \( -perm -1 -or -perm -10 -or -perm -100 \) -print
UX:find: ERROR: Illegal option -- -or
UX:find: TO FIX: Usage: find [path-list] [predicate-list]
$
0
 
ozoCommented:
You're still missing a space between \( and -perm
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
Forgot to mention that I tried this leaving out -type switch in previous attemt but also tried it with it in
$ find . -type f ! \( -perm -1 -or -perm -10 -or -perm -100 \) -print
UX:find: ERROR: Illegal option -- -or
UX:find: TO FIX: Usage: find [path-list] [predicate-list]
$
0
 
ozoCommented:
Ok, can you post your `man find` page
0
 
ozoCommented:
-or might be -o
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
You are THE MAN!

$ find . -type f ! \( -perm -1 -o -perm -10 -o -perm -100 \) -print
./file2
./x
$ ls -l
total 6
-rwxrw-r--    1 barry    users             4 Oct  4 16:30 file1
-rw-rw-r--    1 barry    users             4 Oct  4 16:31 file2
-rw-rw-r-x    1 barry    users             6 Oct  4 16:31 file3
-rw-rw-r--    1 barry    users             0 Oct  4 18:28 x
$

looks like success to me - just double checking

Cheers
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
Could I just get you to fully explain the logic for the bits you pass into each of the -perm switches.
I sort of understand but am a bit hazy


Cheers
0
 
ozoCommented:
100 is u+x
10 is g+x
1 is o+x
0
 
Barry CunneyAuthor Commented:
Hi Ozo,
I was hoping there was something fancy one could do -    +111 is if x bit was set on for u+g+o
I thought there might be some clever way to bitwise NOT this 111 to come up with a single value we could pass into -perm switch to indicated we only wanted  to find files where the u+g+o did NOT have xecute permissions

but your solution does the job anyway - it's a good solution

Cheers
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 12
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now