12.3 mkdir: 創建目錄

 

 

下一篇: mkfifo invocation, 上一篇: ln invocation, 上一级: 特殊文件類型   [目錄][索引]


12.3 mkdir: 創建目錄

mkdir 以指定的名字創建一個目錄。語法:

mkdir [option]… name…

mkdir 按给定的 name 顺序产生目录。 如果指定的 name 名称已存在,则会显示一条错误报告。除非指定了参数 -p 而且 name 是一个目录时不显示错误报告。

這個命令可以接收以下給定的參數。也可參考 通用選項.

-m mode
--mode=mode

设罝创建目录的权限属性为 modechmod 用法相同 ‘a=rwx’ (read, write 和 execute 允许所有用户执行)。参阅 File permissions

默认情况,在目录创建后就会有对应的文件模式位。 Normally the directory has the desired file mode bits at the moment it is created. As a GNU extension, mode may also mention special mode bits, but in this case there may be a temporary window during which the directory exists but its special mode bits are incorrect. See Directory Setuid and Setgid, for how the set-user-ID and set-group-ID bits of directories are inherited unless overridden in this way.

-p
--parents

需要时创建目标目录的上层目录,但即使这些目录已存在也不当作错误处理 需要时创建目标目录的上层目录,如果上层目录已存在不做错误处理。 将新建的文件权限设置为 ‘u+wx’。 不更改文件的权限位。

为了对新建目录的父目录有 ‘u+wx’ 权限,你可以在调用 mkdir 之前设置 umask 的值。例如,shell 命令 ‘(umask u=rwx,go=rx; mkdir -p P/Q)’ 创建父目录 P,同 时将父目录的权限设置为了 ‘u=rwx,go=rx’ 如果想要同时设 置父目录的特殊模式位,你可以在调用 mkdir 之后使用 chmod。参见Directory Setuid and Setgid, 了解新建的父目录 set-user-ID 和 set-group-ID 是如何继承 的。

-v
--verbose

每创建一个新目录就显示一条信息提示。这与 --parents 一起使用十 分有用。

-Z
--context[=context]

在没有指定 上下文 的情况时,根据目录文件的类型,将每个创建的目录 的 SELinux 安全环境设置为 CTX。类似 restorecon 命令。这个选项的长 格式形式,如果指明了特定的上下文,将只会作用于新创建文件的上下文。在指定的上下 文中,如果 SELinux 和 SMACK 都被禁用了,则会出现警告信息。

退出狀态为零表示成功,而非零表示失敗。


下一篇: mkfifo invocation, 上一篇: ln invocation, 上一级: 特殊文件類型   [目錄][索引]

posted @ 2022-11-22 15:49  偊偊而步  阅读(61)  评论(0)    收藏  举报