Short for “make directory”. As the name implies, this command is used to create a new directory when it does not exist. It will warn you when creating a directory that already exists.
General syntax for
$ mkdir [OPTION...] [DIRECTORY...]
Display detailed information of command
-v (verbose) option to see what the
mkdir command is doing in the background.
Example: Printing information about what the command does when creating the
Create multiple directories
mkdir [dir1] [dir2] [dir3]
Create multiple directories by specifying the directory names as command arguments, separated by spaces.
Example: Creating dir1, dir2 and dir3 directories under /Desktop/Command path.
Set directory permissions
mkdir -m [permission] [dir]
-m (-mode) option with the
mkdir command to create a directory with specific permissions.
Example: Let’s create the DirName directory with read-only permission.
Create directory with SELinux context
mkdir -Z [dirname]
This option is used to set default SELinux rules for a specific directory at creation time.
Example: Creating the ExampleDir directory with SELinux context.
Create multi-level directories
mkdir -p [directory_tree]
-p option with the
mkdir command to create a complete directory structure.
Example: Let’s create the directory tree dirname1/dirname2/dirname3, only works if none of these directories already exist.