一个简单的linux命令 mkdir

所属分类: 脚本专栏 / linux shell 阅读数: 1208
收藏 0 赞 0 分享

mkdir 命令用于创建指定名称的目录,要求用户具有要创建的目录下的读写权限。

一、命令格式

mkdir [option] Dir…

二、命令参数

-m, --mode=模式,设定权限<模式> (类似 chmod),而不是 rwxrwxrwx 减 umask
-p, --parents  可以是一个路径名称。此时若路径中的某些目录尚不存在,加上此选项后,系统将自动建立好那些尚不存在的目录,即一次可以建立多个目录; 
-v, --verbose  每次创建新目录都显示信息
--help   显示此帮助信息并退出
--version  输出版本信息并退出

三、命令实例

1.创建目录

命令:mkdir test1

输出:

[root@localhost soft]# cd test
[root@localhost test]# mkdir test1
[root@localhost test]# ll
总计 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1
[root@localhost test]#

2.递归创建多个目录

命令:mkdir -p test2/test22

输出:

[root@localhost test]# mkdir -p test2/test22
[root@localhost test]# ll
总计 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]# ll
总计 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22

3.创建权限为777的目录

命令:mkdir -m 777 test3

输出:

[root@localhost test]# mkdir -m 777 test3
[root@localhost test]# ll
总计 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

4.创建新目录都显示信息

命令:mkdir -v test4

输出:

[root@localhost test]# mkdir -v test4
mkdir: 已创建目录 “test4”
[root@localhost test]# mkdir -vp test5/test5-1
mkdir: 已创建目录 “test5”
mkdir: 已创建目录 “test5/test5-1”

5.一个命令创建项目的目录结构

参考:http://www.ibm.com/developerworks/cn/aix/library/au-badunixhabits.html
命令:
mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}

输出:

[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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

更多精彩内容其他人还在看

关于ssh连不上问题的解决方法(必看)

下面小编就为大家带来一篇关于ssh连不上问题的解决方法(必看)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Ubuntu用户之间相互切换方法(推荐)

下面小编就为大家带来一篇Ubuntu用户之间相互切换方法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Linux 编程之进程fork()详解及实例

这篇文章主要介绍了Linux 编程之进程fork()详解及实例的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

浅谈安装ORACLE时在Linux上设置内核参数的含义

下面小编就为大家带来一篇浅谈安装ORACLE时在Linux上设置内核参数的含义。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

详谈linux中sar的使用方法

下面小编就为大家带来一篇详谈linux中sar的使用方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

设置Linux系统的空闲等待时间TMOUT的方法

下面小编就为大家带来一篇设置Linux系统的空闲等待时间TMOUT的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

关于Linux反空闲设置的两种方法总结

下面小编就为大家带来一篇关于Linux反空闲设置的两种方法总结。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

linux 查找大目录和大文件的方法(推荐)

下面小编就为大家带来一篇linux 查找大目录和大文件的方法(推荐)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Linux makefile 和shell文件相互调用实例详解

这篇文章主要介绍了Linux makefile 和shell文件相互调用实例详解的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享

详解Windows与Linux共享文件夹互相访问

这篇文章主要介绍了 详解Windows与Linux共享文件夹互相访问的相关资料,需要的朋友可以参考下
收藏 0 赞 0 分享
查看更多