Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing only directory permissions in a file hierarchy 1

Status
Not open for further replies.

stackdump

Technical User
Sep 21, 2004
278
GB
I have a very deep database of sub-directories and files which is too big for a chmod. Many of the files have special characters in their names (such as $$). I want to change the permissions on the directories so that people can write into the database, but only let people read what is already in there. The best I can come up with is;

Code:
ls -rR1 | grep -i : | sed -e "s>:>'>" | sed -e "s/.\//chmod 775 '.\//" > dir_list
source ./dir_list

This seems to work, but is there a way of doing this (fairly basic function) just using normal commands?
 
Take a look at the find command:
find . -type d -exec chmod 775 '{}' \;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Chacalinc: When I try and chmod, it says the argument list is too long (the database is very large and very deep).

PHV: Thanks, that looks a lot better. What does the trailing \ mean?
 
What does the trailing \ mean?
man find (the -exec primary)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Got it. The command works fine too, thanks for your help.
 
a faster alternative of that without using -exec (that makes it fork a chmod process on every dir) is using xargs

find . -type d -print0 | xargs -0 -n 10000 chmod 775
if you dont have GNU find, leave out -print0 and -0, would break on spaced dirnames though

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
xmb, I choose the -exec (with single quotes) instead of the xargs because the OP said that many of the filenames contained special characters.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I didnt read that part on my fastfly reading.. GNU -print0 (or any, -printf "%p\0") along with xargs -0 would work. Hmm, isnt -exec GNU too?

. Mac for productivity
.. Linux for developement
... Windows for solitaire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top