Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
09-26-2007, 11:45 AM
|
#1
|
Member
Registered: Jul 2007
Posts: 30
Rep:
|
chmod 775 to only the directories and chmod 664 to only the files?
Hello,
Is there a way to apply chmod 775 to only the directories
and apply chmod 664 to only the files where there a mix of directories and files?
I don't want to do chmod * 775 which will make all the files executable as well.
|
|
|
09-26-2007, 11:52 AM
|
#2
|
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873
|
If you are in the parent directory of the files and directories that you want to change then the following commands will do the job.
For directories only do this.
Code:
find . -type d -exec chmod 775 {} \;
For files only do this.
Code:
find . -type f -exec chmod 664 {} \;
Here you can see that we are selecting which files to affect by using a parameter that selects files by type. The d is for directories and the f is for regular files.
The command for the directories will include the . and the .. directories where you issue the command. Make sure that you check the permissions on your current directory and its parent after you issue the commands.
You can avoid this by providing a wildcard in the command to select the directories. The following command will not affect the . and the .. directories because it does not affect any files whose names begin with a dot.
Code:
find . -type d -name \* -exec chmod 775 {} \;
The find command is the Swiss Army Knife of file manipulation. It has a lot of parameters to select files by lots of different criteria. Then you can use the -exec parameter to send the list of selected files to any other program.
Last edited by stress_junkie; 09-26-2007 at 12:00 PM.
|
|
1 members found this post helpful.
|
09-27-2007, 09:31 AM
|
#3
|
Member
Registered: Jul 2007
Posts: 30
Original Poster
Rep:
|
Awesome! Thanks!
|
|
|
09-27-2007, 09:56 AM
|
#4
|
Member
Registered: Aug 2003
Location: UK
Distribution: (X)Ubuntu 10.04/10.10, Debian 5, CentOS 5
Posts: 900
Rep:
|
If none of the files are set +x at the moment, you could also use the command 'chmod -R +X' (note upper case X). I think this adds execute permission to directories but not files. For whatever reason it doesn't seem to work the other way round, i.e. -X.
|
|
|
09-27-2007, 09:57 AM
|
#5
|
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873
|
Quote:
Originally Posted by Gethyn
If none of the files are set +x at the moment, you could also use the command 'chmod -R +X' (note upper case X). I think this adds execute permission to directories but not files. For whatever reason it doesn't seem to work the other way round, i.e. -X.
|
Sorry Gethyn but that command would add execute permission to all of the files. Why would you think it somehow magically limited itself to directories?
|
|
|
09-27-2007, 10:09 AM
|
#6
|
Member
Registered: Aug 2003
Location: UK
Distribution: (X)Ubuntu 10.04/10.10, Debian 5, CentOS 5
Posts: 900
Rep:
|
Well, according to the manpage for chmod (e.g. here), the option +x (lowercase) adds execute permission to anything, whereas the option +X (uppercase) adds execute permission only if the target is a directory, and does nothing when the target is not a directory. Nothing magical about that. Should've checked that before I posted though, the reason that it does nothing that -X (uppercase) doesn't work is that it's not supposed to, the man page says it's ignored in all cases except +X.
|
|
|
09-27-2007, 03:26 PM
|
#7
|
Senior Member
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873
|
Quote:
Originally Posted by Gethyn
Well, according to the manpage for chmod (e.g. here), the option +x (lowercase) adds execute permission to anything, whereas the option +X (uppercase) adds execute permission only if the target is a directory, and does nothing when the target is not a directory. Nothing magical about that. Should've checked that before I posted though, the reason that it does nothing that -X (uppercase) doesn't work is that it's not supposed to, the man page says it's ignored in all cases except +X.
|
Okay you got me. I should have checked the man page as well.
Quote:
Originally Posted by man page
The letters ‘rwxXstugo' select the new permissions for the affected
users: read (r), write (w), execute (or access for directories) (x),
execute only if the file is a directory or already has execute permis‐
sion for some user (X), set user or group ID on execution (s), sticky
(t), the permissions granted to the user who owns the file (u), the
permissions granted to other users who are members of the file's group
(g), and the permissions granted to users that are in neither of the
two preceding categories (o).
|
|
|
|
All times are GMT -5. The time now is 05:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|