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 |
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.
|
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. |
Look at the man page again and read the section on exec.
|
Or use a loop
Code:
for file in` find..` |
You can also pipe to xargs:
Code:
find /home/ -type d -perm 777 | xargs chmod 755 see my post below for fixing whitespace |
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. |
Quote:
Code:
find /home/ -print0 -type d -perm 777 | xargs -0 chmod 755 |
Or find all that aren't the right permissions and change them.
Code:
|
All times are GMT -5. The time now is 09:18 AM. |