cancel
Showing results for 
Search instead for 
Did you mean: 

scripting question

SOLVED
Go to solution
Kris_5
Occasional Advisor

scripting question

Hi All,

I am trying to write a small command seq. to find out the files which only owner has read/write privs and none other (group/world) has any privileges on the files in a directory and its sub directories. Could some body help me on how to do this. Thanks,

Regards,
Krish
7 REPLIES
Pete Randall
Outstanding Contributor
Solution

Re: scripting question

Krish,

You need to use the find command:

find /starting_dir -perm permissions_desired

Take a look at man find.


Pete


Pete
John Poff
Honored Contributor

Re: scripting question

Hi,

You could try the 'find' command:

find . -user username -perm 0600

where 'username' is the user name you wish to find files for.

JP
Kent Ostby
Honored Contributor

Re: scripting question

I believe you will need a few commands to do this since I dont think you can have wildcards in the permissions field.

find /top_dir -perm 100
find /top_dir -perm 200
find /top_dir -perm 300
find /top_dir -perm 400
...
find /top_dir -perm 700

Best regards,

Kent M. Ostby
"Well, actually, she is a rocket scientist" -- Steve Martin in "Roxanne"
Kris_5
Occasional Advisor

Re: scripting question

Thanks to all for your quick responses. Find command fails if the directory it is checking does not have read/execute priv. Please see below for scenario.

User executing the command is :xyz

$ ll -d /home/oclin/ocusr/test_dir
drwx------ 2 ramon oclin 96 Aug 21 07:00 /home/oclin/opusr/test_dir

$ find ~ -perm 0600 -exec ll {} \;
-rw------- 1 xyz oclin 205614 Aug 21 11:25 /home/oclin/ocusr/.sh_history
-rw------- 1 ramon oclin 0 Aug 20 11:13 /home/oclin/ocusr/abcd.log
find: cannot open /home/oclin/ocusr/test_dir

How do I extend the command to directories also?
GK_5
Regular Advisor

Re: scripting question

find /dir_name -perm perm_mode -print
man find for more details
IT is great!
Pete Randall
Outstanding Contributor

Re: scripting question

Kris,

The obvious answer is to run your find command is root. If that's not possible, I'm at a loss.


Pete


Pete
vasundhara
Frequent Advisor

Re: scripting question

Hi Krish,

you can use -type option of find command to specify file/ directory.

find / -perm -type d -print exec ll {} \; for searching directories and replace "-type d" in the above command with "-type f" for searching normal files.

Regards
VJ.