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]# 
相关推荐
Avan_菜菜21 小时前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
Sokach10151 天前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
SelectDB2 天前
Litefuse 开源并推出单进程轻量模式,25 秒就能跑起来的 Agent 可观测与评估平台
运维·后端·自动化运维
AlfredZhao2 天前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3103 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode3 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
用户0328472220704 天前
如何搭建本地yum源(上)
运维
A小辣椒5 天前
TShark:Wireshark CLI 功能
linux
A小辣椒5 天前
TShark:基础知识
linux
AlfredZhao5 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci