LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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, 07: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, 07: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 07:24 AM.
 
Old 08-11-2008, 07: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, 09: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: 69
Look at the man page again and read the section on exec.
 
Old 08-11-2008, 08:20 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

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

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
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 07:56 AM.
 
Old 08-12-2008, 07:42 AM   #7
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

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

Rep: Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285Reputation: 1285
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, 08: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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 05:50 AM
I changed the permission of root recursively all 777..... how to recover now?? Ankit Sharma Linux - Newbie 16 03-21-2008 05:16 AM
want to avoid 777 permission, but want to write on folder suruchiparimu Linux - Newbie 10 02-09-2006 04:25 AM
BIND 9 Permission denied when chmod is 777 o_O KasperLotus Linux - Networking 10 09-07-2005 01:20 AM
BIND 9 Permission denied when chmod is 777 o_O KasperLotus Linux - Software 0 08-29-2005 12:42 AM


All times are GMT -5. The time now is 09:26 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration