How To Create Directory In Linux Mkdir Tutorial? – POFTUT

How To Create Directory In Linux Mkdir Tutorial?


Linux is all about directories. But how can we create directories in a simple or complex way? How can we create directories in multi-level at a single shot command? We will look at examples of  mkdir command in this post.

mkdir Command Syntax

mkdir [OPTION]... DIRECTORY...
  • OPTION is used to enable/disable mkdir command features like recursive etc.
  • DIRECTORY is the name or path of directory we want to create.

Create Directory with mkdir Command

We create a directory simple using mkdir and directory name. In this example, we will create a directory named test1.

$ mkdir test1

Set File Mode While Creating Directory

While creating a directory it can be set directory permission or mode with -m parameter.

$ mkdir -m=777 test2
Set Mode
Set Mode

Here we set user, group and others permissions and make this all can make read, write, execute which is secure this directory 😉

Create Multiple Level Directories

We may create multilevel directories where intermediate directories do not exist currently. This operation will also create intermediate directories. In this example, we will create a directory hierarchy like test3/test4/test5 where they will be created in a row.

$ mkdir -p test3/test4/test5
Make Parents
Make Parents

Print Verbose

While creating directories there will be no output about the operations. If we need to get more information or verbose output we can use -v option. This will provide a log for each operation for each directory creation.

$ mkdir -v -p test6/test7/test8
Print Verbose
Print Verbose

Set SELinux Context

SELinux provides an extra layer for security. Directory related default context can be set by using -Z .

$ mkdir -Z test9
Set Selinux Context
Set SELinux Context

LEARN MORE  mkdir Command Options For Linux and Windows

4 thoughts on “How To Create Directory In Linux Mkdir Tutorial?”

  1. I must thank you for the efforts you’ve put in writing this blog.
    I’m hoping to check out the same high-grade blog posts by you in the future as well.
    In truth, your creative writing abilities has inspired me to get my
    own, personal site now 😉 sbobet wap

    Reply
  2. You made some good points there. I checked on the web to learn more about the issue and found most individuals will go along with your views on this web site.
    agen bola

    Reply

Leave a Comment