How to create a directory and give permission in single command in Linux?
I have to create lots of folder with full permission 777
.
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.
you can use following command to create directory and give permissions at the same time
mkdir -m777 path/foldername