Create Directory In Linux Mkdir Tutorial
Linux is all about directories. But how can we create directories in simple or complex way? How can we create directories in multi level at a single shot command? We will look examples of mkdir in this post.
mkdir [OPTION]... DIRECTORY...
We create a directory simple using mkdir and directory name.
$ mkdir test1
While creating a directory it can be set directory permission or mode with -m parameter.
$ mkdir -m=777 test2
Here we set user, group and others permissions and make this all can make read, write, execute which is secure this directory 😉
We may create multilevel directories where intermediate directories do not exists currently. This operation will also create intermediate directories.
$ mkdir -p test3/test4/test5
While creating directories especially multi level creation.
$ mkdir -v -p test6/test7/test8
Set Selinux Context
Selinux provides extra layer for security. Directory related default context can be set by using -Z
$ mkdir -Z test9