Q How to set chmod of a/ a/b/ a/b/c/ & a/b/c/d/ to 755
Say I have a path a/b/c/d/ to create
I can call mkdir -p a/b/c/d/ and it will create each of the directory in path
Now I want to set chmod of a/ a/b/ a/b/c/ & a/b/c/d/ to 755
Note mkdir -pm 0755 a/b/c/d/ will set chmod to 755 for only the last folder
Use:
(umask 022; mkdir -p /a/b/c/d)
Setting the umask ensures that the write bits are reset for group and other on any directories the command creates (but has no effect on pre-existing directories, of course). The directories are then created with 755 permissions as desired. The parentheses use a sub-shell so that only the mkdir command is affected by the umask setting. (I use umask 022 by default; I usually don't mind people reading files, but I don't like them changing them without my permission.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With