Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use the mkdir command in Linux

Shulou Source: shulou.com Published: 2022-06-01 05:31:40 09月22日 Update

This article is about how to use the mkdir command in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Linux mkdir command

As mentioned above, users can use the mkdir command to create directories. Its syntax is as follows:

Mkdir [OPTION]... DIRECTORY...

The following is a description of this tool in the man manual:

If the directory does not already exist, create it.

The following Quan An examples will help you better understand how the mkdir command works.

Q1. How do I create a directory using the mkdir command?

Creating a directory is very simple. All you need to do is follow the name of the directory you want to create after the mkdir command as an argument.

Mkdir [dir-name]

Here is a simple example:

Mkdir test-dirQ2. How do I ensure that a parent directory is created when the parent directory does not exist?

Sometimes we need to use a mkdir command to create a complete directory structure, in which case you only need to use the-p command line option.

For example, if you want to create a directory dir1/dir2/dir3, but the parent directory of that directory does not exist, you can do something like this:

Mkdir-p dir1/dir2/dir3

How to make sure parent directories (if non-existent) are created

Q3. How do I customize permissions when creating a directory?

By default, when the mkdir command creates a directory, the permissions are set to rwx, rwx, and rmurx.

How to set permissions for directory being created

However, if you want to customize permissions, you can use the command line option-m.

Mkdir-m command option

Q4. How do I make the mkdir command display operation details?

If you want the mkdir command to show full details of what it does, you can use the-v command line option.

Mkdir-v [dir]

Here is an example:

Thank you for reading! This is the end of this article on "how to use mkdir commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Directories commands examples content permissions more articles details one life help good practical parameters at the same time names that is tools situations manuals articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei Linux Shulou Technology Microsoft