← 返回列表

Linux shell mkdir 命令

Linux shell mkdir 命令用于建立名称为 dirName 之子目录。 mkdir 命令语法 mkdir [-p] dirName 参数 -p 确保目录名称存在,不存在的就建一个。 范例 在工作目录下,建立一个名为 abc 的子目录 : [root@localhost ~]# mkdir abc [root@localhost ~]# ls abc anaconda-ks.cfg shell testfile testfile_1 在工作目录下的 bbb 目录中,建立一个名为 test 的子目录。 若 bbb 目录原本不存在,则建立一个。(注:本例若不加 -p,且原本 bbb 目录不存在,则产生错误。) root@localhost ~]# mkdir bbb/test mkdir: cannot create directory ‘bbb/test’: No such file or directory [root@localhost ~]# mkdir -p bbb/test [root@localhost ~]# tree . . ├── abc ├── anaconda-ks.cfg ├── bbb │ └── test ├── shell │ ├── demo1.sh │ ├── demo2.sh │ ├── demo.cpp │ ├── demo.sh │ ├── main.c │ └── w.sh ├── testfile └── testfile_1 4 directories, 9 files 返回上一级

Linux shell mkdir 命令用于建立名称为 dirName 之子目录。

mkdir 命令语法

mkdir [-p] dirName

参数

-p 确保目录名称存在,不存在的就建一个。

范例

在工作目录下,建立一个名为 abc 的子目录 :

[root@localhost ~]# mkdir abc
[root@localhost ~]# ls
abc  anaconda-ks.cfg  shell  testfile  testfile_1

在工作目录下的 bbb 目录中,建立一个名为 test 的子目录。

若 bbb 目录原本不存在,则建立一个。(注:本例若不加 -p,且原本 bbb 目录不存在,则产生错误。)

root@localhost ~]# mkdir bbb/test
mkdir: cannot create directory ‘bbb/test’: No such file or directory
[root@localhost ~]# mkdir -p  bbb/test
[root@localhost ~]# tree .
.
├── abc
├── anaconda-ks.cfg
├── bbb
│   └── test
├── shell
│   ├── demo1.sh
│   ├── demo2.sh
│   ├── demo.cpp
│   ├── demo.sh
│   ├── main.c
│   └── w.sh
├── testfile
└── testfile_1

4 directories, 9 files

返回上一级

打开资源 ↗

交流与评论