mkdir (make directories)
man mkdir 查看命令使用
命令描述
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, --context=CTX
set the SELinux security context of each created directory to CTX
--help display this help and exit
--version
output version information and exit
创建单个目录mkdir html
[root@guofeng ~]# mkdir html
[root@guofeng ~]# ll
total 68
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
-rw-r--r-- 1 root root 479 Jun 7 06:44 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
drwxr-xr-x 2 root root 4096 Jun 7 18:04 html
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
创建多个目录 mkdir index css images
[root@guofeng ~]# mkdir index css images
[root@guofeng ~]# ll
total 80
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
drwxr-xr-x 2 root root 4096 Jun 7 18:05 css
-rw-r--r-- 1 root root 479 Jun 7 06:44 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
drwxr-xr-x 2 root root 4096 Jun 7 18:04 html
drwxr-xr-x 2 root root 4096 Jun 7 18:05 images
drwxr-xr-x 2 root root 4096 Jun 7 18:05 index
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
创建多个目录第二种方式 mkdir {js,common,plugin}
[root@guofeng ~]# mkdir {js,common,plugin}
[root@guofeng ~]# ll
total 92
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
drwxr-xr-x 2 root root 4096 Jun 7 18:05 common
drwxr-xr-x 2 root root 4096 Jun 7 18:05 css
-rw-r--r-- 1 root root 479 Jun 7 06:44 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
drwxr-xr-x 2 root root 4096 Jun 7 18:04 html
drwxr-xr-x 2 root root 4096 Jun 7 18:05 images
drwxr-xr-x 2 root root 4096 Jun 7 18:05 index
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxr-xr-x 2 root root 4096 Jun 7 18:05 js
drwxr-xr-x 2 root root 4096 Jun 7 18:05 plugin
创建多层级目录 mkdir -p /web/static/html/css
[root@guofeng ~]# mkdir -p /web/static/html/css
[root@guofeng /]# cd web
[root@guofeng web]# ll
total 4
drwxr-xr-x 3 root root 4096 Jun 7 18:13 static
[root@guofeng web]# cd static/
[root@guofeng static]# ll
total 4
drwxr-xr-x 3 root root 4096 Jun 7 18:13 html
[root@guofeng static]# cd html
[root@guofeng html]# ll
total 4
drwxr-xr-x 2 root root 4096 Jun 7 18:13 css
[root@guofeng html]# cd ss
-bash: cd: ss: No such file or directory
[root@guofeng html]# cd css
[root@guofeng css]#
创建文件,显示创建过程mkdir -pv htm/index/css
[root@guofeng ~]# mkdir -pv htm/index/css
mkdir: created directory `htm'
mkdir: created directory `htm/index'
mkdir: created directory `htm/index/css'
[root@guofeng ~]#
创建目录并且设置访问权限 mkdir -m 777 test
[root@guofeng ~]# mkdir -m 777 test
[root@guofeng ~]# ll
total 96
-rw-------. 1 root root 2404 Nov 8 2014 anaconda-ks.cfg
-rw-r--r-- 1 root root 0 Jun 6 18:47 b-ba-c.txt
drwxr-xr-x 2 root root 4096 Jun 7 18:05 common
drwxr-xr-x 2 root root 4096 Jun 7 18:05 css
-rw-r--r-- 1 root root 479 Jun 7 06:44 dump.rdb
-rw-r--r-- 1 root root 0 May 17 07:00 EOF
drwxr-xr-x 3 root root 4096 Jun 7 18:18 htm
drwxr-xr-x 2 root root 4096 Jun 7 18:05 images
drwxr-xr-x 2 root root 4096 Jun 7 18:05 index
-rw-r--r--. 1 root root 39004 Nov 8 2014 install.log
-rw-r--r--. 1 root root 9154 Nov 8 2014 install.log.syslog
drwxr-xr-x 2 root root 4096 Jun 7 18:05 js
drwxr-xr-x 2 root root 4096 Jun 7 18:05 plugin
drwxrwxrwx 2 root root 4096 Jun 7 18:22 test
[root@guofeng ~]#