Linux命令大全: mkdir命令 - 创建目录

1. 详解

mkdir命令是“make directories”的缩写,用来创建目录。

注意:
默认状态下,如果要创建的目录已经存在,则提示已存在,而不会继续创建目录。
所以在创建目录时,应保证新建的目录与它所在目录下的文件没有重名。
mkdir命令还可以同时创建多个目录,是不是很强大呢?

语法格式 : mkdir [参数] [目录]

常用参数:

参数 说明
-p 递归创建多级目录
-m 建立目录的同时设置目录的权限
-z 设置安全上下文
-v 显示目录的创建过程

2. 参考实例

  1. 在工作目录下,建立一个名为 dir 的子目录:
> mkdir dir
  1. 在目录/usr/linuxcool下建立子目录dir,并且设置文件属主有读、写和执行权限,其他人无权访问
> mkdir -m 700 /usr/dreamhai/dir
  1. 同时创建子目录dir1,dir2,dir3:
> mkdir dir1 dir2 dir3
  1. 递归创建目录:
> mkdir -p draemhai/dir

3. 系统文档(mkdir man)

MKDIR(1)                                       User Commands                                      MKDIR(1)

NAME
       mkdir - make directories

SYNOPSIS
       mkdir [OPTION]... DIRECTORY...

DESCRIPTION
       Create the DIRECTORY(ies), if they do not already exist.

       Mandatory arguments to long options are mandatory for short options too.

       -m, --mode=MODE
              set file mode (as in chmod), not a=rwx - umask

       -p, --parents
              no error if existing, make parent directories as needed

       -v, --verbose
              print a message for each created directory

       -Z     set SELinux security context of each created directory to the default type

       --context[=CTX]
              like -Z, or if CTX is specified then set the SELinux or SMACK security context to CTX

       --help display this help and exit

       --version
              output version information and exit

AUTHOR
       Written by David MacKenzie.

REPORTING BUGS
       GNU coreutils online help: //www.gnu.org/software/coreutils/>
       Report mkdir translation bugs to //translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2016  Free  Software  Foundation,  Inc.   License  GPLv3+: GNU GPL version 3 or later
       //gnu.org/licenses/gpl.html>.
       This is free software: you are free to change and redistribute it.  There is NO  WARRANTY,  to  the
       extent permitted by law.

SEE ALSO
       mkdir(2)

       Full documentation at: //www.gnu.org/software/coreutils/mkdir>
       or available locally via: info '(coreutils) mkdir invocation'

GNU coreutils 8.25                             February 2016                                      MKDIR(1)

你可能感兴趣的:(#,Linux,命令,技术栈,linux)