mkdir命令用于创建目录,如同一路径下创建单个或多个目录、递归创建目录,但同路径下不能创建同名目录,且目录名区分大小写。

【命令】

mkdir

【用途】

  创建目录(单个目录/多个目录)

【语法】

mkdir [选项]...目录名...

【示例】

  切换到当前目录:/usr/local/linuxStudy,所有示例在此路径下操作。

[root@testserver linuxStudy]# pwd
/usr/local/linuxStudy

例1.创建单个目录dir1

[root@testserver linuxStudy]# mkdir dir1
[root@testserver linuxStudy]# ls
dir1

例2.一次创建多个目录:dir2,dir3

[root@testserver linuxStudy]# mkdir dir2 dir3
[root@testserver linuxStudy]# ls
dir1 dir2 dir3

例3.同路径下创建同名目录:dir1-->创建失败,同路径下不能创建同名目录

[root@testserver linuxStudy]# mkdir dir1
mkdir: cannot create directory `dir1': File exists

例4.-p参数,创建多层目录dir4/dir5(dir4目录不存在时,同时创建dir4、dir5目录;dir4目录存在时,则只创建dir5目录)

[root@testserver linuxStudy]# mkdir dir4/dir5                           #未加-p参数,上层目录不存在时,创建目录失败
mkdir: cannot create directory `dir4/dir5': No such file or directory
[root@testserver linuxStudy]# mkdir -p dir4/dir5 #-p:上层目录不存在时,同步创建
[root@testserver linuxStudy]# ls -R #-R:递归列出当前目录下所有的目录、文件
.:
dir1 dir2 dir3 dir4 ./dir1: ./dir2: ./dir3: ./dir4:
dir5 ./dir4/
dir5:
[root@testserver linuxStudy]#

例5:-v参数,对于每个创建的目录,打印一条信息

[root@testserver linuxStudy]# mkdir -v dir6
mkdir: created directory `dir6'
[root@testserver linuxStudy]# mkdir -v dir7 dir8
mkdir: created directory `dir7'
mkdir: created directory `dir8'

例6.-m参数,创建目录的同时设置文件权限(同chmod命令)

[root@testserver linuxStudy]# mkdir -m o-rw dir10  #创建dir10目录,other用户去掉rw权限
[root@testserver linuxStudy]# ll
total
drwxr-xr-x root root May : dir1
drwxrwx--x 2 root root 4096 May 9 15:08 dir10
drwxr-xr-x root root May : dir2
drwxr-xr-x root root May : dir3
drwxr-xr-x root root May : dir4
drwxr-xr-x root root May : dir6
drwxr-xr-x root root May : dir7
drwxr-xr-x root root May : dir8
drwxrwxrwx root root May : dir9
[root@testserver linuxStudy]# mkdir -m dir11 #创建dir11目录,设置user、group、other用户权限分别为5、1、1(读权限4,写权限2,执行权限1,用户具备多种权限时值相加)
[root@testserver linuxStudy]# ll
total
drwxr-xr-x root root May : dir1
drwxrwx--x root root May : dir10
dr-x--x--x 2 root root 4096 May 9 15:09 dir11
drwxr-xr-x root root May : dir2
drwxr-xr-x root root May : dir3
drwxr-xr-x root root May : dir4
drwxr-xr-x root root May : dir6
drwxr-xr-x root root May : dir7
drwxr-xr-x root root May : dir8
drwxrwxrwx root root May : dir9

【帮助文档】

Linux环境下输入 man mkdir,查看find命令的帮助文档(ps:英文渣渣咬咬牙啃一啃帮助文档。不要偷懒,多看官方文档。注释部分为个人添加。)

[root@testserver local]# man mkdir
MKDIR() User Commands 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 #设置文件权限,而不是默认权限a=rwx -p, --parents
no error if existing, make parent directories as needed
#父目录不存在时,创建所需的父目录 -v, --verbose
print a message for each created directory #对每一个创建的目录打印1条信息 -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 AUTHOR
Written by David MacKenzie. REPORTING BUGS
Report mkdir bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report mkdir translation bugs to <http://translationproject.org/team/> COPYRIGHT
Copyright © Free Software Foundation, Inc. License GPLv3+: GNU GPL version or later
<http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permit-
ted by law. SEE ALSO
mkdir() The full documentation for mkdir is maintained as a Texinfo manual. If the info and mkdir programs are prop-
erly installed at your site, the command info coreutils 'mkdir invocation' should give you access to the complete manual. GNU coreutils 8.4 November MKDIR()
(END)

【写在末尾】

文章如有错误之处,欢迎评论指正。

有兴趣可关注同名微信公众号“粒粒的测试笔记”,号内会分享各种测试相关知识,感谢关注。

【Linux】1 创建目录:mkdir的更多相关文章

  1. Linux C 创建目录函数mkdir相关(转-清新居士)

    I.Linux C 创建目录函数mkdir的mode设置问题 函数原型: #include <sys/stat.h> int mkdir(const char *path, mode_t ...

  2. Linux C 创建目录函数mkdir相关【转】

    转自:http://blog.csdn.net/fallenink/article/details/8480483 原文地址:http://sharp2wing.iteye.com/blog/1280 ...

  3. Linux命令学习-mkdir命令

    Linux中,mkdir命令的全称是make directory,即创建目录的意思. 假设当前处于wintest用户的主目录,路径为 /home/wintest ,存在文件夹testA,进入testA ...

  4. Linux 命令之 mkdir

    mkdir的作用是创建一个目录,可以理解为 make directory 的缩写. 创建目录 mkdir dir_name 在当前目录创建一个名为 dir_name 的目录. 同时创建多级目录 假设现 ...

  5. 每天一个Linux命令(mkdir)

    每天一个Linux命令(mkdir) mkdir: /bin/mkdir,创建目录( make directories)语法:mkdir [选项]... 不存在的目录...目录:默认时必须该目录不存在 ...

  6. 在 Linux 下用 mkdir 命令来创建目录和子目录

    mkdir 是什么呢 Mkdir 是一个用来在 Linux 系统下创建目录的命令.此命令属于内建命令. 运行 mkdir 命令 你可以在你的控制台直接键入 mkdir 来使用它. $ mkdir 默认 ...

  7. 工作中常用的Linux命令:mkdir命令

    本文链接:http://www.cnblogs.com/MartinChentf/p/6076075.html (转载请注明出处) 在Linux系统中,mkdir命令用来创建一个目录或一个级联目录. ...

  8. linux命令:mkdir 命令详解

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...

  9. (转)每天一个Linux命令(4): mkdir

    http://www.cnblogs.com/peida/archive/2012/10/25/2738271.html linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前 ...

  10. 每天一个linux命令:mkdir

    linux mkdir 命令用来创建指定的名称的目录,要求创建目录的用户在当前目录中具有写权限,并且指定的目录名不能是当前目录中已有的目录. 1.命令格式: mkdir [选项] 目录... 2.命令 ...

随机推荐

  1. mybatis一级缓存让我憔悴

    Mybatis对缓存提供支持,是默认开启一级缓存. 来一段代码,这边使用的是mybatis-plus框架,通过构建 QueryWrapper 查询类来实现的. @Transactional publi ...

  2. 解决项目迁移至Kubernetes集群中的代理问题

    解决项目迁移至Kubernetes集群中的代理问题 随着Kubernetes技术的日益成熟,越来越多的企业选择用Kubernetes集群来管理项目.新项目还好,可以选择合适的集群规模从零开始构建项目: ...

  3. @SessionAttributes 的使用

    @SessionAttributes 注解只用作用在 类 上,作用是将指定的 Model 的键值对保存在 session 中.可以让其他请求共用 session 中的键值对. 指定保存的属性名 作用是 ...

  4. mysql 使用记录

    修改 mysql 数据库密码 mysqladmin -u username -h host_name password -P <port> "new_password" ...

  5. python学习19类5之多态与鸭子模型

    '''''''''一.多态1.Python中多态是指一类事物有多种形态.''' class Animal: def run(self): raise AttributeError('子类必须实现这个方 ...

  6. 修改CENTOS7的网卡ens33修改为eth0

    1.先编辑网卡的配置文件将里面的NAME DEVICE项修改为eth0 vim /etc/sysconfig/network-scripts/ifcfg-ens33 2.[root@linux-nod ...

  7. BIOS和CMOS区别

    在网上看到一篇关于CMOS的文章,分享一下. 原文地址:http://jingyan.baidu.com/article/c843ea0b51155d77921e4a7a.html BIOS是什么? ...

  8. java关于throw Exception的一个小秘密

    目录 简介 throw小诀窍 总结 java关于throw Exception的一个小秘密 简介 之前的文章我们讲到,在stream中处理异常,需要将checked exception转换为unche ...

  9. Spring5参考指南:容器扩展

    文章目录 BeanPostProcessor自定义bean BeanFactoryPostProcessor自定义配置元数据 使用FactoryBean自定义实例化逻辑 Spring提供了一系列的接口 ...

  10. 华硕笔记本无法U盘启动,快捷键识别不了

    http://www.udaxia.com/upqd/8254.html 转载于:https://www.cnblogs.com/wanglinjie/p/10507888.html