Skip to main content

mkdir command

mkdir - Make or Create Directory(ies)

Create the DIRECTORY(ies), if they do not already exist.

Usage: mkdir [OPTION]... DIRECTORY...

$ mkdir --help
Usage: mkdir [OPTION]... DIRECTORY...
Create the DIRECTORY(ies), if they do not already exist.

Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE set file mode (as in chmod), not a=rwx - umask
-p, --parents no error if existing, make parent directories as needed
-v, --verbose print a message for each created directory
-Z set SELinux security context of each created directory
to the default type
--context[=CTX] like -Z, or if CTX is specified then set the SELinux
or SMACK security context to CTX
--help display this help and exit
--version output version information and exit
  • mkdir - Make directory.

    username@linux:~$ mkdir newfolder
    username@linux:~$ ls
    newfolder
  • mkdir -p - The -p or --parents flag, adds some powerful functionality to this command in creating multiple levels of directories by creating all parent directories that do not exist.

    username@linux:~$ mkdir -p way/to/new/directory

    If way, way/to, or way/to/new do not exist, mkdir -p will create them automatically, ensuring that the final directory way/to/new/directory exists.

    username@linux:~$ mkdir -p /home/user/project/{src,bin,docs}
    username@linux:~$ cd /home/user/project
    username@linux:~/home/user/project$ ls
    bin docs src

    This command would create a project directory under /home/user, and within project, it would create src, bin, and docs directories, all in one go, without throwing an error if any of these directories already exist.