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]# 
相关推荐
轻松Ai享生活2 小时前
5 节课深入学习Linux Cgroups
linux
christine-rr3 小时前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神5553 小时前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆3 小时前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
qq_264220893 小时前
LVS负载均衡群集和LVS+Keepalived群集
运维·负载均衡·lvs
乌萨奇也要立志学C++3 小时前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器
雨落Liy3 小时前
Nginx 从入门到进阶:反向代理、负载均衡与高性能实战指南
运维·nginx·负载均衡
Yyyy4824 小时前
Nginx负载均衡集群实验步骤
运维·nginx·负载均衡
獭.獭.5 小时前
Linux -- 信号【上】
linux·运维·服务器
hashiqimiya5 小时前
centos配置环境变量jdk
linux·运维·centos