System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

how to get rid of unnecessary permission

 
SOLVED
Go to solution
Highlighted
Valued Contributor

how to get rid of unnecessary permission

/data contains 35 subdirectories, and each subdirectory contains hundreds files.

I made joe the owner of /data, then I allowed joe for rwx and no access to other users

# chmod -R 700 /data

no issue yet, but the above command set the execute permission on every file(text, jpg, png, pdf etc) under /data/sub-directories
and I dont like unnecessary execute permissions on files.

so in short how can I run "chmod -R 700 /data" without the 'x'(unnecessary) permission on text/jpg/png/pdf files

any suggestion/tip/recommendation would be highly appreciated

Regards
Maaz
5 REPLIES 5
Highlighted
Honored Contributor
Solution

Re: how to get rid of unnecessary permission

"chmod 700 without the 'x'" is "chmod 600".

At this point, you will have to construct a command that sets "chmod 600" for files only (not directories). For this, you'll need the "find" command.

You did not identify your Linux distribution, so I'll have to give you a preferred generic form of the command. It's a bit long, but should work in even very old versions of Linux:

find /data -type f -print0 | xargs -0 chmod 600

A shorter form (may or may not work, depending on which version of the "find" command is installed in your Linux distribution):

find /data -type f -exec chmod 600 {} \+

An inefficient form that works, but should be avoided when dealing with large numbers of files:

find /data -type f -exec chmod 600 {} \;

(yes, that single character makes a lot of difference!)

A tip for the future: using octal numeric permissions with the -R option of chmod is likely to give you a headache. When doing recursive changes, you should state what you mean in another way. Instead of your original command, you might have wanted to do this:

chmod -R u=rwX,go-rwx /data

meaning:
- for the _u_ser that owns the files, give r and w access; also give x permission IF the target is a directory OR already has some x permissions set
- remove all other permissions

MK
MK
Highlighted
Acclaimed Contributor

Re: how to get rid of unnecessary permission

>"chmod -R 700 /data" without the 'x'(unnecessary) permission on text/jpg/png/pdf files

You shouldn't use "chmod -R", it will only get you into trouble, unless you have something simple like "chmod -R a+r"

To remove permissions, you could use find with particular suffixes:
find /data \( -name "*.pdf" -o -name "*.txt" \) -exec chmod a-x \;
Highlighted
Valued Contributor

Re: how to get rid of unnecessary permission

Hi Matti Kurkela
thanks for the excellent help

>You did not identify your Linux distribution
its SLES10 SP2, and RHEL 4.6

>find /data -type f -exec chmod 600 {} \+
from a "find tutorial"

The semicolon closes the -exec instruction. Because this is a special character, it is
masked by placing a backslash in front of it.


but what "\+" does ?

Hi Dennis Handly, thanks for the help, and suggestions.

Regards
Highlighted
Acclaimed Contributor

Re: how to get rid of unnecessary permission

>but what "\+" does?

(You don't need that "\" before the "+".)

If you have a real OS that is Unix branded, the "+" char allows multiple files to be passed to the program under -exec. For HP-UX:
http://docs.hp.com/en/B2355-60130/find.1.html#d0e85142
Highlighted
Exalted Contributor

Re: how to get rid of unnecessary permission

Shalom Maaz,

This is a link to a Bill Hassell hpux system configuration document.

http://www.hpux.ws/?p=12

Before you walk away from it, it has a great script for identifying files with questionable permissions that will work on Linux.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com