LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to scan /home for folders with 777 permission (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-scan-home-for-folders-with-777-permission-661960/)

jeff80 08-11-2008 06:15 AM

script to scan /home for folders with 777 permission
 
Hello

How can I prepare a script which will scan /home for folders with 777 permission and then it will set 755 permissions on those folders.

command find /home/ -type d -perm 777

will scan the /home for folders with 777 permission, but know I need to set 755 permission on this folders.

Please help in resolving this issue.

Thank you

Regards!
Jeff80

beadyallen 08-11-2008 06:23 AM

This sounds a little like homework, but have a look at 'man find'. Specifically, you can search for files with certain permissions with 'find [directory] -perm [permissions]'. Then use the '-exec' construct in find to convert the permissions.

jeff80 08-11-2008 06:38 AM

Hi

The following command will find the folders with 777 permission

find /home/ -type d -perm 777

but I need know to set permission 755 on the folders which are found after executing the above command.

I am quite new to scripting, Please if anyone can help in getting to the point.

chort 08-11-2008 08:54 AM

Look at the man page again and read the section on exec.

chrism01 08-11-2008 07:20 PM

Or use a loop
Code:

for file in` find..`
do
    chmod ...
done

see http://tldp.org/LDP/Bash-Beginners-G...tml/index.html and man page for chmod

H_TeXMeX_H 08-12-2008 05:08 AM

You can also pipe to xargs:

Code:

find /home/ -type d -perm 777 | xargs chmod 755
EDIT:
see my post below for fixing whitespace

theYinYeti 08-12-2008 06:42 AM

I wouldn't do as suggested by chrism01 and H_TeXMeX_H. It's asking for trouble because of paths with spaces inside. I'd rather do

find … -print | while read path; do … ; done

or (if I need to be able to modify the current environment):

while read path; do … ; done < <(find … -print)

But then, of course, neither is needed in this case. As said before, look for the '-exec' option in find man page; there's not much to it und it's the answer.

Yves.

H_TeXMeX_H 08-12-2008 06:55 AM

Quote:

Originally Posted by theYinYeti (Post 3244711)
I wouldn't do as suggested by chrism01 and H_TeXMeX_H. It's asking for trouble because of paths with spaces inside.

Oh, good point, here's a good way to fix white space issues:

Code:

find /home/ -print0 -type d -perm 777 | xargs -0 chmod 755

mijohnst 02-26-2015 07:02 PM

Or find all that aren't the right permissions and change them.

Code:


find /home -maxdepth 1 -mindepth 1 -type d -not -perm 755 | xargs chmod 755



All times are GMT -5. The time now is 09:18 AM.