Home > System Tutorial > LINUX > body text

Quickly master the usage skills of Linux command mkdir

WBOY
Release: 2024-03-19 15:06:04
Original
866 people have browsed it

Linux system is an operating system widely used in servers and personal computers, with rich command line tools. Among them, the mkdir command is one of the common commands used to create directories. This article will introduce how to quickly master the usage skills of the mkdir command, and attach specific code examples.

1. Basic syntax

The basic syntax of mkdir is as follows:

mkdir [option] directory name
Copy after login

where, [Option] indicates optional parameters, and the directory name is the name of the directory to be created. The following are some commonly used options:

  • -p: Create a directory recursively, and automatically create it if the parent directory does not exist
  • -m: Specify permission mode

2. Create a single directory

To create a single directory, just follow the command with the directory name:

mkdir mydir
Copy after login

3. Recursively create a directory

If you want to create a multi-level nested directory, you can use the -p option:

mkdir -p mydir1 /mydir2/mydir3
Copy after login

4. Specify the permission mode

You can use the -m option to specify the permission mode of the directory, such as:

mkdir -m 755 mydir
Copy after login

5. Use with other commands The

mkdir command can also be used with other commands, such as && and ||:

Create the directory and output the success message:

mkdir mydir && echo "Directory creation successful" 
Copy after login

Create the directory, if the creation fails, output the error message:

mkdir existingdir || echo "Directory creation failed"
Copy after login

6. Practical application example

Example 1: Create a directory named test

mkdir test
Copy after login

Example 2: Recursively create the /data/files directory

mkdir -p /data/files
Copy after login

Example 3: Create a docs directory with permissions rwxr-xr-x

mkdir -m 755 docs
Copy after login

Conclusion

Through this article Introduction, I believe readers have mastered the basic usage of the mkdir command and some common techniques. In daily use, flexible use of the mkdir command can manage the directory structure more efficiently. I hope the above content is helpful to you, and you are welcome to continue learning and exploring other commands and techniques in Linux systems.

The above is the detailed content of Quickly master the usage skills of Linux command mkdir. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template