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.
The basic syntax of mkdir
is as follows:
mkdir [option] directory name
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 modeTo create a single directory, just follow the command with the directory name:
mkdir mydir
If you want to create a multi-level nested directory, you can use the -p
option:
mkdir -p mydir1 /mydir2/mydir3
You can use the -m
option to specify the permission mode of the directory, such as:
mkdir -m 755 mydir
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"
Create the directory, if the creation fails, output the error message:
mkdir existingdir || echo "Directory creation failed"
test
mkdir test
/data/files
directorymkdir -p /data/files
docs
directory with permissions rwxr-xr-x
mkdir -m 755 docs
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!