Create directories with mkdir command

by Daniel Pham
Published: Updated:
This entry is part 3 of 4 in the series Linux commands: Part 4 - Manipulating files and directories

To create a directory in Linux, use the command mkdir – this command is an acronym for “make directory”. mkdir command is pretty simple to use and this article is for beginners to become familiar with Linux.

mkdir’s syntax

Basic command syntax is as follows:

mkdir directory...

A note on notation: When three periods follow an argument in the description of a command (as above), it means that the argument can be repeated, thus:

mkdir dir1

would create a single directory named dir1, while

mkdir dir1 dir2 dir3

would create three directories named dir1, dir2, and dir3.

Options of the mkdir command

To display the full options of the mkdir command, use the following command:

mkdir --help

Create folder with permissions

Here, the article only gives you a brief overview of permissions in Linux. Normally, we will use the chmod command to set permissions.

There are three user levels:

  • Owner
  • Group
  • Other

There are three possible settings:

  • Read – has a value of 4
  • Write – has a value of 2
  • Execute – has a value 1
table chmod calculator
Table chmod calculator.

As the image above, you see the permissions set to have a value of 755. What does this mean? This means that the user is the owner who has permissions including read, write, execute (4 + 2 + 1). Group members have the permissions to read and execute (4 + 1) and other users have the permission to read and execute.

The mkdir command supports the -m parameter, so you can set permissions right at the time of creating that directory.

  • -m, --mode=MODE: set file mode (as in chmod), not a=rwx – umask
use mkdir command with -m option
Use mkdir command with -m option.

You can see above that I set the permissions for directory name dir1 is 755, and permissions for directory name dir2 is 700.

Create directory without parent directory

Mkdir support a parameter that is useful -p, this parameter allows you to create subfolders without concern that the parent directory exists or not. Because it will create both the parent directory and the subdirectory at the same time.

Recommended Reading: Copy files and directories with “cp” command

use mkdir command to create folder without parent
Use mkdir command to create folder without parent.

As you can see, when I run mkdir command withou -p, it return error.


Although the mkdir command is very simple and with the examples above we can create folders with more options. That is the option that probably few people use but very useful.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating
Series Navigation«« Previous part: Move and rename in Linux with mv commandNext part: Remove files and directories with rm command »»

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.