Using mkdir -m -p and chown together correctly

我的梦境 提交于 2019-12-08 15:15:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!