On Unix-like operating systems, the mkdir command creates new directories in a file system.
This page covers the GNU/Linux version of mkdir.
Syntax
mkdir [-m=mode] [-p] [-v] [-Z=context] directory [directory …]
mkdir –version
mkdir –help
Options
Exit status
mkdir returns an exit status of zero if all operations were successful, or a non-zero exit status if operations failed.
- Syntax
- Options
- Exit status
- Examples
- Related commands
- Linux commands help
Examples
mkdir myfiles
Create a new directory named myfiles in the current directory.
mkdir ~/myfiles
Create the directory myfiles in your home directory, specified here with a tilde ("~"). For more information about using ~ to represent your home directory, see tilde expansion in bash.
mkdir -m a=rwx mydir
Create the mydir directory, and set its file mode (-m) so that all users (a) may read (r), write (w), and execute (x) it.
For directories, this means that users on the system may view (“read”), and create/modify/delete (“write”) files in the directory. Users may also change to (“execute”) the directory, for example with the cd command.
chdir -m 777 mydir
Same as the command above, but using a numerical file mode. Grants read, write, and execute permissions to the directory for all users. (For more information about file modes, see chmod).
mkdir -p /home/hope/Documents/pdf
Creates the directory /home/hope/Documents/pdf. If any of the parent directories /home, /home/hope, or /home/hope/Documents do not already exist, they are automatically created.
Related commands
rmdir — Remove a directory.