LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2008, 06:15 AM   #1
jeff80
LQ Newbie
 
Registered: Jan 2008
Posts: 12

Rep: Reputation: 0
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
 
Old 08-11-2008, 06:23 AM   #2
beadyallen
Member
 
Registered: Mar 2008
Location: UK
Distribution: Fedora, Gentoo
Posts: 209

Rep: Reputation: 36
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.

Last edited by beadyallen; 08-11-2008 at 06:24 AM.
 
Old 08-11-2008, 06:38 AM   #3
jeff80
LQ Newbie
 
Registered: Jan 2008
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 08-11-2008, 08:54 AM   #4
chort
Senior Member
 
Registered: Jul 2003
Location: Silicon Valley, USA
Distribution: OpenBSD 4.6, OS X 10.6.2, CentOS 4 & 5
Posts: 3,660

Rep: Reputation: 76
Look at the man page again and read the section on exec.
 
Old 08-11-2008, 07:20 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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
 
Old 08-12-2008, 05:08 AM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
You can also pipe to xargs:

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

Last edited by H_TeXMeX_H; 08-12-2008 at 06:56 AM.
 
Old 08-12-2008, 06:42 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 66
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.
 
Old 08-12-2008, 06:55 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Quote:
Originally Posted by theYinYeti View Post
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
 
Old 02-26-2015, 07:02 PM   #9
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Rep: Reputation: 31
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't execute c++ binaries, "permission denied"... even though permission is 777 SerfurJ Programming 14 02-20-2009 04:50 AM
I changed the permission of root recursively all 777..... how to recover now?? Ankit Sharma Linux - Newbie 16 03-21-2008 04:16 AM
want to avoid 777 permission, but want to write on folder suruchiparimu Linux - Newbie 10 02-09-2006 03:25 AM
BIND 9 Permission denied when chmod is 777 o_O KasperLotus Linux - Networking 10 09-07-2005 12:20 AM
BIND 9 Permission denied when chmod is 777 o_O KasperLotus Linux - Software 0 08-28-2005 11:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration