Solved

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

Posted on 2004-10-01
21
385 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
  • 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

856 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