Linux mkdir Command

In this tutorial, we will learn about Linux mkdir Command in Linux and we will also cover different examples related to mkdir command.

Linux mkdir Command

In Linux, mkdir stands for make directory. The Name Suggest the purpose of mkdir command is to create a directory.

Syntax:

mkdir directory_name


In the above syntax, directory_name can be anything or as per your required name what we want to give to the project or any folder to save the files under that directory.

Let us understand about the mkdir command using the following examples:

Example 1.0:

In this example we are creating a directory with a name “mydir” and to create this we use the following command to proceed to create this directory.

mkdir mydir

By running the above command it will create the directory at the current location with the name “mydir“.

Output:

After running the following command we can see in the below output that the directory “mydir” is created inside the /demo location.

mkdir command
mkdir command

Creating Multiple Directories

We heard many times in the interviews and even in the viva many person ask the question that Can we create the Multiple Directories at the same time using the single command?

So we have the answer to this question and we will explain this with an example.

The answer is simple yes we can create the multiple directories at the same time using the single command. To understand this properly we can follow the following example below:

Example 1.2:

In this example we are creating the multiple directories with the name “D1”, “D2”, “D3” using the single command.

Syntax:

mkdir D1 D2 D3

By running the above command we will able to create the three directories at the same time into the current location we want to create.

creating multiple directories in linux
Multiple Directories

In the above output we can see that the Directories D1,D2,D3 are created inside the /demo location.

Read: Linux Directory

Creating Directory from current location to other location

In the above topics and the examples we have learned the command to create a directory and a multiple directories but now we are going to show an example to create a directory from the present location to the other location of our system.

Let us suppose that my current location is /demo and I want to create the directory “EXAMPLE3” at location “/home/shivanshu/examples”

To perform this we only need to add the path with the mkdir command.To see this how we can do follow the below syntax:

mkdir /home/shivanshu/EXAMPLE3

Output:

In the below output we can see our current location is /demo and from there we have created a directory inside /home/shivanshu/examples/ in the below output the following example is also known as the Parent Directory of EXAMPLE3 directory.

Creating Directory from current location to other location
Creating Directory from current location to other location

Creating E4 directory inside E3 directory

Note:

While we proceed further please note that the E3 directory does not exist.

Example:

In this example we are required to create E4 directory inside the E3 directory by using the single command.

  • To perform this first we will create a directory E3 then we will go inside that directory and then after we will create a E4 directory at the E3 location.
  • Let us clear that the E3 is also known as the parent directory of the E4 so we are also require to create a parent directory as well with the mkdir command and to make this we can use the -p option.

Syntax:

mkdir -p E3/E4

In the above syntax the -p option will tell mkdir that if the parent directory does not exist then it first need to create that so, this command first creates E3 directory at the current location and the E4 directory inside E3 directory.

Output:

In the below output we can see that the E4 directory is created inside the E3 directory using the single command.

Linux Parent directory

Tasks for Practice

  • What will be the output of command mkdir t1, however t1 directory already exists at current location.
  • What will be the output of command mkdir /t1, however t1 directory already exists at current location and your current location is /demo.
  • What will be the output of command mkdir -p t1/t2, however t1 directory already exists at current location.

So, in this tutorial, we discussed Linux mkdir command and we have also covered different examples related to its implementation. Here is the list of topics that we have covered.

  • Linux mkdir Command
  • Creating Multiple Directories
  • Creating Directory from current location to other location
  • Tasks for Practice
  • Creating E4 directory inside E3 directory

477 thoughts on “Linux mkdir Command”

  1. My developer is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on numerous websites for about a year and am nervous about switching to another platform. I have heard excellent things about blogengine.net. Is there a way I can transfer all my wordpress content into it? Any kind of help would be really appreciated!

    Reply
  2. Несомненно актуальные события мировых подиумов.
    Актуальные мероприятия известнейших подуимов.
    Модные дома, бренды, гедонизм.
    Свежее место для стильныех людей.
    https://hypebeasts.ru/

    Reply
  3. Wow that was strange. I just wrote an very long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyways, just wanted to say superb blog!

    Reply
  4. Полностью трендовые события подиума.
    Абсолютно все мероприятия лучших подуимов.
    Модные дома, торговые марки, гедонизм.
    Приятное место для стильныех людей.
    https://modastars.ru/

    Reply
  5. Точно свежие новости индустрии.
    Актуальные эвенты известнейших подуимов.
    Модные дома, торговые марки, гедонизм.
    Свежее место для стильныех хайпбистов.
    https://donnafashion.ru/

    Reply
  6. Точно актуальные события индустрии.
    Абсолютно все мероприятия известнейших подуимов.
    Модные дома, торговые марки, высокая мода.
    Новое место для модных людей.
    https://donnafashion.ru/

    Reply
  7. Самые трендовые новинки индустрии.
    Абсолютно все мероприятия всемирных подуимов.
    Модные дома, торговые марки, гедонизм.
    Приятное место для стильныех людей.
    https://lecoupon.ru/

    Reply
  8. Hi, I think your site might be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, fantastic blog!

    Reply
  9. I used to be very happy to search out this internet-site.I wished to thanks in your time for this wonderful learn!! I positively enjoying every little bit of it and I have you bookmarked to take a look at new stuff you blog post.

    Reply
  10. Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and return to read more of your useful info. Thanks for the post. I will definitely return.

    Reply
  11. Unquestionably believe that that you stated. Your favourite reason appeared to be on the net the simplest thing to take into accout of. I say to you, I definitely get irked at the same time as other folks consider issues that they just don’t know about. You managed to hit the nail upon the highest as neatly as outlined out the whole thing with no need side effect , other folks can take a signal. Will probably be back to get more. Thanks

    Reply
  12. Whenever I go on my computer after a few minutes (I’d say about 5) it just restarts for some reason. I’ve tried to restore my computer but can’t because it will restart before it finishes. How can i stop the restarting or reatore my computer when this is happening Someone please help.

    Reply
  13. hello!,I like your writing very much! share we be in contact extra about your article on AOL? I require a specialist in this space to solve my problem. May be that is you! Taking a look ahead to see you.

    Reply
  14. You can certainly see your enthusiasm in the work you write.
    The world hopes for even more passionate writers such as you who aren’t afraid to mention how they believe.
    All the time go after your heart.

    Reply
  15. Бренд Balenciaga — это выдающимся домов высокой моды, который создался в первой половине 20 века испанским дизайнером Кристобалем Баленсиагой. Бренд известен экстравагантными моделями и авангардными кроями, нарушают стандартам индустрии.
    https://balenciaga.whitesneaker.ru/

    Reply

Leave a Comment