Home  >  Article  >  System Tutorial  >  Usage and examples of Linux command mkdir

Usage and examples of Linux command mkdir

WBOY
WBOYOriginal
2024-03-19 21:12:03356browse

Title: Usage and examples of Linux command mkdir

In the Linux operating system, mkdir is a commonly used command for creating new folders or directories. Through the mkdir command, users can create a new directory structure at any location to facilitate management of files and data. This article will introduce the basic usage and examples of the mkdir command to help readers better understand and master the use of this command.

1. Basic syntax

mkdirThe basic syntax of the command is as follows:

mkdir [option] Directory name

Where, [Option] is an optional parameter, Directory name is the name of the new directory to be created.

2. Common options

  • -p: Create a directory recursively, that is, if the superior directory of the directory to be created does not exist, the superior directory will be automatically created.
  • -m: Set the permission mode of the new directory.
  • -v: Display detailed information during the creation process.

3. Example

Example 1: Create a new directory in the current directory

Assume that you are currently in the user's home directory and you want to create a directory named ## To create a new directory for #Documents, you can use the following command:

mkdir Documents
After executing this command, a new directory named 

Documents will be created in the current directory. New directory.

Example 2: Recursively create multi-level directories

Suppose you want to create a new directory

project/notes under the /home/user directory, you can Use the -p option to recursively create multi-level directories:

mkdir -p /home/user/project/notes
This command will be in 

/home/ Create a directory named project under the user directory, and then create a subdirectory named notes under the project directory.

Example 3: Set the permission mode of the new directory

If you want to create a new directory named

data under the current directory, and set the permissions to rwxr-xr-x, you can use the -m option:

mkdir -m 755 data
This command will create a 

data directory , and set its permissions to rwxr-xr-x (755).

Example 4: Display detailed information

If you want to view the detailed process of creating a new directory, you can use the

-v option. For example, create a new directory named images and display detailed information:

mkdir -v images
After executing this command, the creation of 

images will be displayed Directory details.

Through the above examples, readers can understand the basic usage and common options of the

mkdir command, and flexibly use this command to create and manage the directory structure according to actual needs. I hope this article can help readers become more proficient in using the mkdir command in Linux systems.

The above is the detailed content of Usage and examples of Linux command mkdir. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn