Solved

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

Posted on 2004-10-01
21
386 Views
Last Modified: 2010-04-21
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
Comment
Question by:Barry Cunney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
21 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 12206706
! -perm +111
! -perm +ugo+x
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12217745
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
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12217929
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 12222291
I think I said +111 not -111
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12224777
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
 
LVL 84

Expert Comment

by:ozo
ID: 12225004
What version of find/unix are you using?
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12225651
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
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12225670
Ho Ozo,
The date of the 'find' file in bin directory is Oct 12 1999 and the size is 15484


Cheers
0
 
LVL 84

Accepted Solution

by:
ozo earned 50 total points
ID: 12225948
I do not have access to SCO Unix to test this, but try:
! \( -perm -1 -or -perm -10 -or -perm -100 \)
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226123
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
 
LVL 84

Expert Comment

by:ozo
ID: 12226212
Space between !  \( -perm and -100 \)
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226251
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
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226270
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
 
LVL 84

Expert Comment

by:ozo
ID: 12226282
You're still missing a space between \( and -perm
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226320
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
 
LVL 84

Expert Comment

by:ozo
ID: 12226329
Ok, can you post your `man find` page
0
 
LVL 84

Expert Comment

by:ozo
ID: 12226347
-or might be -o
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226386
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
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226413
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
 
LVL 84

Expert Comment

by:ozo
ID: 12226500
100 is u+x
10 is g+x
1 is o+x
0
 
LVL 17

Author Comment

by:Barry Cunney
ID: 12226543
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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

761 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question