"Daniel D Jones" <[EMAIL PROTECTED]> writes: > I've been using Linux for awhile but every thing I know is self taught. That > means I know some things quite well and am abysmally ignorant in other areas. > Hopefully, this question isn't too stupid. Or maybe it'll give you a good > laugh and you'll take pity on me and answer anyway! > > I want to set specific permissions on a group of directories and all > sub-directories. I can't figure out how to do this other than manually > tracing through the directory tree. > > As near as I can tell, chmod has no option to select only directories. I > figured I'd use ls to list the directories and pipe them to chmod, but ls > doesn't seem to be able to do it either. Surely I'm missing something. ls > _has_ to have the equivalent of the DOS command "dir /a:d". Doing "info ls", > "Which files are listed" shows only -a, -A, -B, -d, -I, -L, -R, none of which > seem to be able to suppress listings based upon permissions or types. > > The closest I could figure out was to do: > > ls | grep ^d > > However, trying to use that method to extract only the directory names and > then pipe them to chmod would have gotten quite convoluted. > > So, the primary question is, is there an easy way to set the permission on > directories, only directories, and all sub-directories? A related question > is how to use ls to list only directories.
Well, in Unix you typically string a bunch of simple tools together to accomplish complex tasks. You almost had it with your "ls" solution, but try "find" instead, and use xargs. Here's how I do what you're trying to accomplish: find <dirname> -depth -type d -print|xargs chmod 770 > And if anyone's in a 'splaining mood, here's another one: how do you set all > files so that the group permissions match the user permissions? (If you have > three files who's permissions are, for example, 700, 600, 500, and you want > them to be 770, 660, 550 respectively.) This one is tougher, I think. I'd write a script to do it. Maybe someone has a brighter idea. The complication here is that there's not a good shell command, or unix utility, to simply report the mode of a file in numerical form, at least that I'm aware of. You could write such a utility pretty easily in C using the "stat()" function, but even though it's simple it seems like over kill. Gotta be a better way. Gary -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]