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.
Basic command syntax is as follows:
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:
would create a single directory named
mkdir dir1 dir2 dir3
would create three directories named
Options of the mkdir command
To display the full options of the
mkdir command, use the following command:
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:
There are three possible settings:
- Read – has a value of 4
- Write – has a value of 2
- Execute – has a value 1
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.
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
You can see above that I set the permissions for directory name
755, and permissions for directory name
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
As you can see, when I run
mkdir command withou
-p, it return error.
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.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.