Create directories with mkdir command

Share this post to your friends !

This entry is part 3 of 4 in the series Linux commands: Part 4 - Manipulating files and directories

WriteBash - 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
create-directories-with-mkdir-command-01 Create directories with mkdir command
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
create-directories-with-mkdir-command-02 Create directories with mkdir command
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.

create-directories-with-mkdir-command-03 Create directories with mkdir command
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.

Continue reading the series«« Previous part: Move and rename in Linux with mv commandNext part: Remove files and directories with rm command »»
If you liked this article, then please subscribe to our YouTube Channel for more video tutorials. You can also find us on Twitter and Facebook.

Share this post to your friends !
If you appreciate what we share in this blog, you can support us by:
  1. Stay connected to: Facebook | Twitter | Google Plus | YouTube
  2. Subscribe email to recieve new posts from us: Sign up now.
  3. Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
  4. Become a Supporter - Make a contribution via PayPal.
  5. Support us by purchasing Ribbon Lite Child theme being using on this website.

We are thankful for your support.

single post bottom banner
«« »»

Got something to say? Join the discussion

Please keep in mind that all comments are subject to our Comment Policy. Your email address will not be published.
This site uses Akismet to reduce spam. Learn how your comment data is processed.