Linux(Centos 7.6)命令详解:mkdir

1.命令作用

如果目录还不存在,则创建目录(Create the DIRECTORY, if they do not already exist.)

2.命令语法

Usage: mkdir [OPTION]... DIRECTORY...

3.参数详解

OPTION:

  • -m, --mode=MODE,创建新目录同时设置权限模式
  • -p, --parents,创建多层目录,如上层目录不存在会自动创建
  • -v, --verbose,创建目录时打印目录创建信息
  • -Z,没有具体英文单词,是一个选项标志,用于创建一个带selinux上下文的目录

4.常用用例

1.-m参数,创建一个指定mode的目录

复制代码
[root@localhost test]# mkdir -m 777 Dir1
[root@localhost test]# ll
total 0
drwxrwxrwx. 2 root root 6 Jan  6 13:55 Dir1
[root@localhost test]# 

2.-p参数,创建多层目录

复制代码
[root@node2 test]# ll
total 0
[root@node2 test]# mkdir Dir1/Dir2/Dir3
mkdir: cannot create directory 'Dir1/Dir2/Dir3': No such file or directory
[root@node2 test]# mkdir -p Dir1/Dir2/Dir3
[root@node2 test]# tree 
.
└── Dir1
    └── Dir2
        └── Dir3

3 directories, 0 files
[root@node2 test]# 

3.-v参数,创建目录输出创建信息

复制代码
[root@node2 test]# mkdir -v Tdir1
mkdir: created directory 'Tdir1'
[root@node2 test]# 

4.一次多次创建多个同级目录

复制代码
[root@node2 test]# ll
total 0
[root@node2 test]# mkdir Dir1 Dir2 Dir3
[root@node2 test]# ll
total 0
drwxr-xr-x. 2 root root 6 Jan  6 14:04 Dir1
drwxr-xr-x. 2 root root 6 Jan  6 14:04 Dir2
drwxr-xr-x. 2 root root 6 Jan  6 14:04 Dir3
[root@node2 test]# 
相关推荐
撰卢2 分钟前
【个人笔记】负载均衡
运维·笔记·负载均衡
lilian12942 分钟前
linux系统mysql性能优化
linux·运维·mysql
共享家95271 小时前
linux_线程概念
linux·开发语言·jvm
乌云暮年2 小时前
Linux常用命令
linux·服务器·ssh·php
weixin_516023072 小时前
Geant4 安装---Ubuntu
linux·运维·ubuntu
稀液蟹-plus2 小时前
zynq-PS篇——bperez77中DMA驱动注意事项
linux·fpga
wanhengidc2 小时前
企业选择大带宽服务器租用的原因有哪些?
运维·服务器
罗技1232 小时前
用Filebeat OSS 7.10.2将收集日志到Easysearch
运维·es
brave_zhao2 小时前
JavaBeanUtils javaBean转map, 实体类转map,实体集合转List<Map>
linux·windows·python
egoist20233 小时前
【Linux仓库】虚拟地址空间【进程·陆】
linux·运维·服务器·操作系统·进程·虚拟地址空间·fork