LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   CHMOD with an exclude? (https://www.linuxquestions.org/questions/linux-general-1/chmod-with-an-exclude-375454/)

nicedreams 10-21-2005 11:27 AM

CHMOD with an exclude?
 
Is there a way to CHMOD everything in a directory except for two directories?

Like on my web server I need to set 'chmod 707 -Rv .' but want to exclude egroupware and maybe another dir in the furture.

That seems the fastest way to me or I can go through 100 files and have to chmod them one at a time, but this is Linux and I know it's flexable enough for that.

cdhgee 10-21-2005 11:36 AM

I would have thought the easiest thing to do is to chmod everything in the directory as you described, then unchmod the two directories that you don't want included.

nicedreams 10-21-2005 01:54 PM

How do I unchmod something then?

I hope you don't mean reset the permissions, because egroupware and some other apps are very picky about their permissions on the web server and won't run unless they are perfect.

cdhgee 10-21-2005 02:03 PM

I did mean reset the permissions. Just note what the permissions were beforehand, then reset them afterwards. You could automate this using a fairly straightforward shell script.

trexdude_99 06-15-2016 09:28 AM

CHMOD with an exclude
 
I know this thread is old, but this solution is still relevant to anyone who may be searching for the same thing. Do a find on the directory and pipe it to egrep -v to exclude a string then pipe to xargs to chown/chmod everything but the directory you want to exclude.

find /usr/directory | egrep -v "somedirectory" | xargs -i /bin/chmod 770 {} 2>/dev/null

Habitual 06-15-2016 09:48 AM

Quote:

Originally Posted by trexdude_99 (Post 5561226)
find /usr/directory | egrep -v "somedirectory" | xargs -i /bin/chmod 770 {} 2>/dev/null

Whoa. Welcome to LQ!
But your suggested command is NOT SAFE for web servers on public-facing networks.
and the permissions are non-standard on a web server.
files = 644
directories (are also files) = 755
with VERY FEW exceptions.

Code:

find /path -type d ! -name somedirectory -exec chmod 755 {} \;
Enjoy the Goodness.

trexdude_99 06-15-2016 05:34 PM

@Habitual

My code was posted as an example of what could be done, and not meant to be specific to a web server. Maybe you should let the OP know that 707 is non-standard and not safe also?

ondoho 06-16-2016 01:36 AM

neither 707 nor 770 are safe.
i'm with habitual: it's important to point these things out in the most vehement terms possible.
don't post this even as "as an example of what could be done".
because people will go and actually do it.

Habitual 06-16-2016 11:22 AM

Quote:

Originally Posted by trexdude_99 (Post 5561506)
@Habitual

My code was posted as an example of what could be done, and not meant to be specific to a web server.

Examples. Yes, lovely examples. Arbitrary code from (sometimes) arbitrary fora pasted into arbitrary terminals,
by a guy who wants to "chmod 707 -Rv ." except for two directories sourced from "some guy" with 2 posts?
The net is dangerous enough.
And wtf 770?
Double Secret Probation!

nicedreams:
Warning: Do not even think about running
Code:

chmod 707 -Rv .
or
Code:

find /usr/directory | egrep -v "somedirectory" | xargs -i /bin/chmod 770 {} 2>/dev/null

It is not my recommendation.

In the interest of fairness,
Why 707? and what 2 directories?
What are you reading and where are you reading it?


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