您的位置:首页 > 运维架构 > Shell

mkdir 创建目录(文件夹)

2015-12-30 11:03 501 查看
短选项长选项含义
-m <目录属性>--mode <目录属性>建立目录时同时设置目录的权限。
-p--parents此选项后,可以是一个路径名称。

若路径中的某些目录尚不存在,系统将自动建立好那些尚不存在的目录。

即一次可以建立多个目录。
-v--verbose每次创建新目录都显示信息
实例1:创建一个空目录 
[root@localhost test]# [code]mkdir test1
 
[root@localhost test]#
ls -l
 
总计 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1 
 
实例2:创建多层目录 
[root@localhost test]#
mkdir -p test2/test22
 
[root@localhost test]#
ls -l
 
总计 8drwxr-xr-x 2 root root 4096 10-25 17:42 test1 
drwxr-xr-x 3 root root 4096 10-25 17:44 test2 
[root@localhost test]# cd test2/ 
[root@localhost test2]# ls -l 
总计 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22 
 
实例3:创建权限为777的目录 
[root@localhost test]#
mkdir -m 777 test3
 
[root@localhost test]# ls -l 
总计 12drwxr-xr-x 2 root root 4096 10-25 17:42 test1 
drwxr-xr-x 3 root root 4096 10-25 17:44 test2 
drwxrwxrwx 2 root root 4096 10-25 17:46 test3 
说明:test3 的权限为rwxrwxrwx 
 
实例4:创建新目录都显示信息 
[root@localhost test]#
mkdir -v test4
 
mkdir: 已创建目录 “test4” 
[root@localhost test]#
mkdir -vp test5/test5-1
 
mkdir: 已创建目录 “test5” 
mkdir: 已创建目录 “test5/test5-1” 
 
 
实例五:一个命令创建项目的目录结构 
[root@localhost test]#
mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}

mkdir: 已创建目录 “scf” 
mkdir: 已创建目录 “scf/lib” 
mkdir: 已创建目录 “scf/bin” 
mkdir: 已创建目录 “scf/doc” 
mkdir: 已创建目录 “scf/doc/info” 
mkdir: 已创建目录 “scf/doc/product” 
mkdir: 已创建目录 “scf/logs” 
mkdir: 已创建目录 “scf/logs/info” 
mkdir: 已创建目录 “scf/logs/product” 
mkdir: 已创建目录 “scf/service” 
mkdir: 已创建目录 “scf/service/deploy” 
mkdir: 已创建目录 “scf/service/deploy/info” 
mkdir: 已创建目录 “scf/service/deploy/product” 
[root@localhost test]#
tree scf/
 
scf/ 
|-- bin 
|-- doc 
|   |-- info 
|   `-- product 
|-- lib 
|-- logs  
|   |-- info 
|   `-- product 
`-- service 
      `-- deploy 
        |-- info 
         `-- product 
 
12 directories, 0 files 
[/code]

 
创建多层目录
目录结构:当前目录/test1/test2
[code]mkdir -p test1/test2


同等级多个目录
当前目录/
|--test1
|--test12
|--test13
mkdir {test1,test12,test13}


创建多层多个目录
当前目录/
|--test1
|--test2
|--test12
|--test13
mkdir -p {test1/test2,test12,test13}


当前目录/
|--test1
|--test2
|--test3
|--test12
|--test22
|--test13
mkdir -p {test1/test2/test3,test12/test22,test13}


当前目录下,并存test1、tes1t12、test13三个目录。
test1目录下,存在test2。另外在test2目录下,存在test3.
test12目录下,存在test22。[/code]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Shell基础