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]# 
相关推荐
JZC_xiaozhong11 分钟前
企业多系统审批流程如何打通?一文详解跨系统流程自动化方案
运维·自动化·流程自动化·数据集成与应用集成·业务流程管理·流程设计可视化·流程监控
weixin_5160230718 分钟前
电子阻止本领 electronic stopping power
linux
信创天地18 分钟前
AI + 信创双轮驱动:从自主可控到智能引领,重塑数字经济新范式
运维·人工智能·网络安全·系统架构·系统安全·运维开发
开开心心就好19 分钟前
免费无广告卸载工具,轻便安全适配全用户
linux·运维·服务器·网络·安全·启发式算法·1024程序员节
硬核子牙23 分钟前
ebpf检测Linux系统要来了
linux
↘"LYong33 分钟前
Centos升级Redis(7.4.1 ---> 7.4.6)
linux·redis
bedynamic34 分钟前
Ubuntu虚拟机磁盘空间不足解决方案
linux·ubuntu
我不是稻草人38 分钟前
Centos共享Mac文件
linux·macos·centos
only°夏至besos40 分钟前
MySQL 运维实战:常见问题排查与解决方案
运维·数据库·mysql
鱼大虾42 分钟前
centos服务器安装gitlab
服务器·centos·gitlab