Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the mkdir command to create directories and subdirectories under Linux

Shulou Source: shulou.com Published: 2022-06-01 02:58:27 09月30日 Update

This article mainly introduces how to use the mkdir command to create directories and subdirectories under Linux. It is very detailed and has a certain reference value. Interested friends must finish reading it!

What is mkdir?

Mkdir is a command used to create a directory on a Linux system. This command is a built-in command.

Run the mkdir command

You can use it by typing mkdir directly in your console.

$mkdir

By default, running the mkdir command without any parameters creates a directory under the current directory. The following is a reference example:

As you can see from the figure above, we have created a directory called office. When we run the mkdir command, we are in the / home/pungki directory. So the new directory office is created in the / home/pungki directory. If we use an absolute path-for example: / usr/local -, Linux creates a directory under the / usr/local directory.

When Linux discovers that the directory you want to create already exists, Linux prompts us that Linux cannot create it.

Another first condition for creating a directory is that you must have access to the destination path where you want to create the directory. Mkdir will report this error when you cannot get permission.

Create multiple directories

We can also create multiple directories at the same time. For example, the directories we are going to create are ubuntu, redhat and slackware. Then the grammar would look like this:

$mkdir ubuntu redhat slackware

Add a directory containing subdirectories [translation note: recursively create a directory]

You need to use the-p parameter when the directory you want to create contains subdirectories. If mkdir cannot find the parent directory, this parameter will first help create the parent directory. For example, we want to create a directory called letter, which contains a subdirectory important. Then the grammar would look like this:

$mkdir-p letter/important

Set access permissions

Using the-m parameter, we can set permissions for the new directory to be generated. Examples are as follows:

$mkdir-masking r Murray-letter

The above command creates a directory called letter and gives read-only permissions to directory owners, user groups, and other users

Print process information for creating a directory

If we want to view the information, we can use the-v parameter to do so. Examples are as follows:

$mkdir-v ubuntu redhat slackware

The above is all the contents of the article "how to use the mkdir command to create directories and subdirectories under Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Directories commands subdirectories subdirectories parameters permissions examples runs information content at the same time multiple appearance users articles syntax paths references help above Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Redmi Xiaomi vpn OPPO Reno