mkdir makes new directories. Directories keep related files together, and you will create them constantly.
Making a directory
$ mkdir projects
$ ls -F
projects/Success is silent. ls -F adds a / after directory names.
You can create several at once:
$ mkdir docs images musicEach argument is a separate directory, so quote a name containing spaces: mkdir "Holiday Photos".
When it fails
If the name is already taken, you get an error:
$ mkdir projects
mkdir: cannot create directory โprojectsโ: File existsIt also fails if a parent directory is missing:
$ mkdir work/2026/june
mkdir: cannot create directory โwork/2026/juneโ: No such file or directoryCreating parents with -p
-p creates any missing parents along the way, and does not complain if the directory already exists:
$ mkdir -p work/2026/juneThis makes work, then 2026, then june. It is very handy in scripts, which may run more than once. It still fails if an ordinary file is in the way.
-v reports each directory as it is created:
$ mkdir -pv a/b
mkdir: created directory 'a'
mkdir: created directory 'a/b'Permissions
New directories get default permissions that are limited by your umask, often giving drwxr-xr-x or drwxrwxr-x. Use -m to set the mode of the new directory directly:
$ mkdir -m 700 private
$ ls -ld private
drwx------ 2 pete pete 4096 Nov 29 11:00 privateMode 700 lets only the owner read, write and enter it. With -p, -m applies to the final directory, not to the parents it creates.
Brace expansion
Bash can expand one word into several before mkdir sees it:
$ mkdir -p site/{css,js,img}
$ ls site
css img jsDo not put spaces inside the braces. This is a shell feature, so it may not work in a basic sh.
You can practise in the files and links lab.
Try it
- Create a directory called
practice. - Inside it, make
a/b/cwith one command. - Create a private directory with mode
700. - Use braces to create three sibling directories.
Check your understanding
mkdir (Make Directory)
All 4 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.