I have a question regarding mkdir -p
with the -m
option or with a change on umask to 227.
When I want to create multiple folders like /tmp/test1/test2 and want all the newly created folders to have 550, how do I do it?
Because, when I run mkdir -pm 550 /tmp/test1/test2
just the last created folder has 550 and all others are created with 750. Same is, when I change the umask
to 227
. Just the last created folder has the 550 I wanted all to have.
Could someone please explain it to me?
Many thanks in advance.
kind regards Joerg
mkdir manpage is clear on that:
-p, --parents
no error if existing, make parent directories as needed, with
their file modes unaffected by any -m option.
So -m doesn't affect parent directories. You have to create all parent directories manually although in your specific example setting mode on the parent directory will prevent creating a final directory because 550 doesn't grant write permission on the parent directory.