Using mkdir -m -p and chown together correctly
34,575
Solution 1
It goes a little like this:
install -d -m 0755 -o someuser -g somegroup /dir/dir2
Solution 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.
Author by
jquery
Updated on September 17, 2020Comments
-
jquery almost 4 years
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?