每天一命令(3) mkdir (make directories) 1分鐘

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 ~]# 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章