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]# 
相关推荐
Lenyiin20 分钟前
Linux 项目托管 `git`
linux·运维·服务器·git·lenyiin
Blossom.11821 分钟前
基于时序大模型+强化学习的虚拟电厂储能调度系统:从负荷预测到收益最大化的实战闭环
运维·人工智能·python·决策树·机器学习·自动化·音视频
阿达_优阅达1 小时前
集成方案 | 通过 Xtract Universal,将 SAP 数据无缝接入 Power BI 与微软 Fabric
运维·microsoft·sap·fabric·theobald
莫翊痕8 小时前
DNF服务端跑五国重复报IP127.0.0.1和20403,20203....
centos
网络小白不怕黑8 小时前
Docker容器网络:四大模式解析与自定义网络
运维·docker·容器
徐子元竟然被占了!!8 小时前
Linux-systemctl
linux·数据库·oracle
_w_z_j_11 小时前
Linux----mmap
linux
FeelTouch Labs12 小时前
Nginx核心架构设计
运维·前端·nginx
程序员zgh12 小时前
Linux系统常用命令集合
linux·运维·服务器·c语言·开发语言·c++
gwd20012 小时前
如何快速设置 Docker 代理设置
运维·人工智能·docker·容器