问题
I would like to create a directory using a bash script and then set the mode to 00755 at the same time
mkdir -p -m=00755 "/dir/dir2"
Is this the correct way of using them together and can I also add chown command to the same line while creating them?
回答1:
It goes a little like this:
install -d -m 0755 -o someuser -g somegroup /dir/dir2
回答2:
If you want to set the owner during creation, you can simply impersonate as this user, using sudo
for example:
sudo -uTHE_USER mkdir -p -m=00755 "/dir/dir2"
This has the advantage that there will be no time difference between creation and changing the ownership, which could otherwise being harmful if exploited.
回答3:
Yes that should work. As for the chown, simply follow the command ' && chown... '. && is similar to ; except the next command ONLY executes if the previous command exits success (0).
来源:https://stackoverflow.com/questions/25873479/using-mkdir-m-p-and-chown-together-correctly