How to Create a New Folder Using Terminal

How to Create a New Folder Using Terminal

In the previous section, we have learned how to View the Contents of a Folder, and move to a folder. This time we will learn how to create a directory or folder in Linux in Terminal using command line interface.

If you take a look at the post List of Basic Linux Commands and Their Functions, you will see a command called mkdir. Order mkdir this is what has the function to create a new folder using command line interface.

To use it you can write it by adding the name of the folder you want to create in front of it, for example you want to create a directory called “folder1”, you can do this by using the command:

mkdir folder1

To prove whether the “folder1” folder has been created, you can check it by using the command ls as we learned earlier:

ls

Then the contents of the directory where you are currently will appear, a folder named “folder1” will appear as shown below, which means we have successfully created a folder using command line interfaces:

Creating a Folder Using the mkdir Command
Creating a Folder Using the mkdir Command

Order mkdir can also be used to create multiple folders together in the same directory.

Creating Multiple Folders Using the Mkdir Command

Suppose you want to create three more folders named “folder2”, “folder3”, and “folder4” again in the directory you are currently in. You can do this by using a command like the following:

mkdir folder2 folder3 folder4

Then 3 new folders will be created as you want. To prove it, you can check it by using the “ls” command as shown in the image below:

Creating Multiple Folders Simultaneously
Creating Multiple Folders Simultaneously

This means that we have succeeded in creating 3 folders simultaneously as we wanted before.

Next, how to create a folder automatically reference. As we learned earlier, the structure of reference directory also applies to the command mkdir.

Creating a Folder in a Folder By Reference

For example, you want to create a sub folders of “folder1” named “sub” and this “sub” folder has sub folders again named “child”. You can make it using a command like the following:

mkdir -p folder1/sub/child

To make sure you can check it by using the “ls” command like this:

ls folder1/sub

Then the contents of the “folder1/sub/” directory that we created earlier will appear as shown below, which means we have succeeded in creating a directory structure as we want:

Creating Folders By Reference Using the mkdir Command
Creating Folders By Reference Using the mkdir Command

This method also applies if you want to create a longer directory structure, you only need to separate the names sub folders from every parent folders using the sign slash “/”.

By using the command mkdiryou can also create a directory that has a complex structure using only one command line, for example you want to create a directory structure like in the image below:

Directory or Folder Structure
Directory or Folder Structure

You can do this by using the command mkdir using only one command line. For how, you can see in the tutorial How to Create Multiple Folders Using One Command in Linux.

That’s all for the Terminal Learning tutorial section this time. We have learned how to create a directory or folder, then we will learn how to create a file using command line interface on Linux.

Tinggalkan Balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *