Linux is all about directories. But how can we create directories in a simple or complex way? How can we create directories in multi-level at a single shot command? We will look at examples of mkdir
command in this post.
Linux全部与目录有关。 但是,我们如何以简单或复杂的方式创建目录? 我们如何通过一次单击命令就可以在多层目录中创建目录? 我们将看一些例子 这篇文章中的mkdir
命令。
mkdir命令语法 (mkdir Command Syntax)
mkdir [OPTION]... DIRECTORY...
OPTION
is used to enable/disable mkdir command features like recursive etc.OPTION
用于启用/禁用mkdir命令功能,例如递归等。DIRECTORY
is the name or path of directory we want to create.DIRECTORY
是我们要创建的目录的名称或路径。
使用mkdir命令创建目录 (Create Directory with mkdir Command)
We create a directory simple using mkdir
and directory name. In this example, we will create a directory named test1
.
我们使用mkdir
和目录名称创建一个简单的目录。 在此示例中,我们将创建一个名为test1
的目录。
$ mkdir test1
在创建目录时设置文件模式 (Set File Mode While Creating Directory)
While creating a directory it can be set directory permission or mode with -m parameter.
创建目录时,可以使用-m参数设置目录权限或模式。
$ mkdir -m=777 test2
Here we set user, group and others permissions and make this all can make read, write, execute which is secure this directory 😉
在这里,我们设置用户,组和其他权限,并使所有这些都可以使该目录安全地进行读取,写入和执行。
创建多个级别目录 (Create Multiple Level Directories)
We may create multilevel directories where intermediate directories do not exist currently. This operation will also create intermediate directories. In this example, we will create a directory hierarchy like test3/test4/test5 where they will be created in a row.
我们可能会创建当前不存在中间目录的多级目录。 此操作还将创建中间目录。 在此示例中,我们将创建一个目录层次结构,如test3 / test4 / test5,在其中将在一行中创建它们。
$ mkdir -p test3/test4/test5
打印详细(Print Verbose)
While creating directories there will be no output about the operations. If we need to get more information or verbose output we can use -v
option. This will provide a log for each operation for each directory creation.
创建目录时,将不会有关于操作的输出。 如果需要获取更多信息或详细输出,可以使用-v
选项。 这将为每个目录创建的每个操作提供一个日志。
$ mkdir -v -p test6/test7/test8
设置SELinux上下文(Set SELinux Context)
SELinux provides an extra layer for security. Directory related default context can be set by using -Z
.
SELinux提供了额外的安全层。 可以使用-Z
来设置与目录相关的默认上下文。
$ mkdir -Z test9
翻译自: https://www.poftut.com/create-directory-linux-mkdir-tutorial/