昨日:每天学一个 Linux 命令(15):man
命令简介
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命令在日常的应用过程,基本上都是创立目录,没有其它罕用的用处。所以,这个命令把握起来也比较简单,易学、易上手。
每天学一个 Linux 命令(14):cat
每天学一个 Linux 命令(13):touch
每天学一个 Linux 命令(12):chown