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?
3 Answers
It goes a little like this:
install -d -m 0755 -o someuser -g somegroup /dir/dir2 5If 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.
3Yes 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).
1