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

Set permissions on directories, but not files

SOLVED
Go to solution
Robert_Jewell
Honored Contributor

Set permissions on directories, but not files

I have a series of directories and files, many with different permissions set. What I would like to do is set all directories to 755, while keeping the files set to 744.

Can I do this in one command or must I run chmod -R 755 and then go to each directory and removing the 'x' value from each file afterward?

Thanks in advance!

-Bob
----------------
Was this helpful? Like this post by giving me a thumbs up below!
4 REPLIES
Patrick Wallek
Honored Contributor
Solution

Re: Set permissions on directories, but not files

Use find.

cd /somedir
find . -type d -exec chmod 755 {} +
James R. Ferguson
Acclaimed Contributor

Re: Set permissions on directories, but not files

Hi Bob:

You could do something like:

# find /path -xdev -type d -exec chmod 755 {} +

This will recursively descend '/path' but not cross any mountpoints ('-xdev') looking for directories (' -type d') and when found, change the permissions to 755.

Regards!

...JRF...
Robert_Jewell
Honored Contributor

Re: Set permissions on directories, but not files

Thanks guys. Probably should have thought of that :-),

-Bob
----------------
Was this helpful? Like this post by giving me a thumbs up below!
Bill Hassell
Honored Contributor

Re: Set permissions on directories, but not files

> while keeping the files set to 744.

Are you saying that all the files in these directories are scripts? Never set the execute bit on data files, only on scripts. There are a number of nasty side effects to having data files set to executable. The correct mode would be 644, not 744.


Bill Hassell, sysadmin