How to create a directory and give permission in single command

后端 未结 8 1949
日久生厌
日久生厌 2021-01-29 23:27

How to create a directory and give permission in single command in Linux?

I have to create lots of folder with full permission 777.

Commands

相关标签:
8条回答
  • 2021-01-30 00:02

    Don't do: mkdir -m 777 -p a/b/c since that will only set permission 777 on the last directory, c; a and b will be created with the default permission from your umask.

    Instead to create any new directories with permission 777, run mkdir -p in a subshell where you override the umask:

    (umask u=rwx,g=rwx,o=rwx && mkdir -p a/b/c)
    

    Note that this won't change the permissions if any of a, b and c already exist though.

    0 讨论(0)
  • 2021-01-30 00:05

    you can use following command to create directory and give permissions at the same time

    mkdir -m777 path/foldername 
    
    0 讨论(0)
提交回复
热议问题