Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
Showing results for 
Search instead for 
Did you mean: 

scripting question

Go to solution
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,

Pete Randall
Outstanding Contributor

Re: scripting question


You need to use the find command:

find /starting_dir -perm permissions_desired

Take a look at man find.


John Poff
Honored Contributor

Re: scripting question


You could try the 'find' command:

find . -user username -perm 0600

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

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"
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?
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


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


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.