Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change chmod of directories in path

Tags:

linux

perl

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

like image 740
Atul Gupta Avatar asked Oct 17 '25 16:10

Atul Gupta


1 Answers

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.)

like image 66
Jonathan Leffler Avatar answered Oct 19 '25 07:10

Jonathan Leffler