如何在Linux Mkdir教程中创建目录?

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
Set Mode
Set Mode
设置模式

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
Make Parents
Make Parents
做父母

打印详细(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
Print Verbose
Print Verbose
打印详细

设置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
Set Selinux Context
Set SELinux Context
设置SELinux上下文
LEARN MORE  mkdir Command Options For Linux and Windows
了解更多用于Linux和Windows的mkdir命令选项

翻译自: https://www.poftut.com/create-directory-linux-mkdir-tutorial/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值