每天学一个 Linux 命令(16):mkdir
发布日期:2021-07-01 03:52:58 浏览次数:2 分类:技术文章

本文共 1690 字,大约阅读时间需要 5 分钟。

点击上方“民工哥技术之路”,选择“设为星标”

回复“1024”获取独家整理的学习资料!

昨日:

命令简介

mkdir 命令用于创建新目录。创建目录时,如果目录名前没有指定路径,那么就直接在当前工作目录下创建新的目录。如指定了路径,那么就会在这个指定的目录下创建一个新目录。

创建目录是需要注意,你所创建的目录名与当前目录下的文件名没有重名,如果有重名,系统会出现如下的提示,无法创建成功。

[root@centos7 test]# ls -ltotal 0-rw-r--r-- 1 root root 0 Jan  2 07:06 test[root@centos7 test]# mkdir testmkdir: cannot create directory ‘test’: File exists

命令语法

mkdir [选项] [目录名]mkdir [option] [directory]

选项说明

-m,--mode=模式 #设定权限
<模式>
(类似 chmod)-p,--parents #可以是一个路径名称,递归创建目录,可以创建目录路径不存在的目录,即一次可以建立多个目录;-v,--verbose #显示创建目录的创建过程信息--help #显示帮助信息并退出--version #输出版本信息并退出

应用举例

创建新目录(一个目录)

[root@centos7 ~]# mkdir testdir[root@centos7 ~]# ls -ltotal 21884-rw-------.  1 root root     1320 Aug 20 10:39 anaconda-ks.cfgdrwxr-xr-x   2 root root        6 Jan  2 07:12 testdir

一次创建多个目录

[root@centos7 ~]# cd testdir[root@centos7 testdir]# ls[root@centos7 testdir]# mkdir test1 test2 test3 test4[root@centos7 testdir]# lstest1  test2  test3  test4[root@centos7 testdir]# mkdir -p test6/{1..5}[root@centos7 testdir]# tree test6test6├── 1├── 2├── 3├── 4└── 55 directories, 0 files

递归创建目录,当上一级目录不存在时,需要使用递归参数

[root@centos7 testdir]# mkdir test5/testmkdir: cannot create directory ‘test5/test’: No such file or directory[root@centos7 testdir]# mkdir -p test5/test[root@centos7 testdir]# tree.├── test1├── test2├── test3├── test4└── test5    └── test6 directories, 0 files

创建目录时,并配置其权限

#创建的新目录,默认权限是755[root@centos7 test5]# lltotal 0drwxr-xr-x 2 root root 6 Jan  2 07:16 test[root@centos7 test5]# mkdir -m 777 test1[root@centos7 test5]# lltotal 0drwxr-xr-x 2 root root 6 Jan  2 07:16 testdrwxrwxrwx 2 root root 6 Jan  2 07:38 test1

mkidr命令在日常的使用过程,基本上都是创建目录,没有其它常用的用途。所以,这个命令掌握起来也比较简单,易学、易上手。

推荐阅读 点击标题可跳转

转载地址:https://mingongge.blog.csdn.net/article/details/112597758 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:微信出硬件了!或于春节上线
下一篇:职场防坑指南(2020 版)

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年05月01日 23时28分10秒