Linux常用基本命令( mkdir )

Posted ghostwu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux常用基本命令( mkdir )相关的知识,希望对你有一定的参考价值。

mkdir:

作用:创建目录( make directories )

命令格式: make [option] 目录

1,创建目录, 当目录存在时,再次创建会提示文件已经存在

[email protected]:~/linux/mkdir$ ls
[email protected]:~/linux/mkdir$ tree -d
.

0 directories
[email protected]:~/linux/mkdir$ mkdir a
[email protected]:~/linux/mkdir$ ls
a
[email protected]:~/linux/mkdir$ mkdir a
mkdir: cannot create directory ‘a’: File exists

2,可以一次性创建多个目录

[email protected]:~/linux/mkdir$ ls
a
[email protected]:~/linux/mkdir$ mkdir b c d
[email protected]:~/linux/mkdir$ ls
a  b  c  d

3,当一个目录的上级目录不存在时候,需要用-p 递归创建

[email protected]:~/linux/mkdir$ ls
a  b  c  d
[email protected]:~/linux/mkdir$ mkdir e/test
mkdir: cannot create directory ‘e/test’: No such file or directory
[email protected]:~/linux/mkdir$ ls
a  b  c  d
[email protected]:~/linux/mkdir$ mkdir -p e/test
[email protected]:~/linux/mkdir$ tree
.
├── a
├── b
├── c
├── d
└── e
    └── test

4,-v 输出创建目录过程的详细信息

[email protected]:~/linux/mkdir$ mkdir f/a/b/c -pv
mkdir: created directory f
mkdir: created directory f/a
mkdir: created directory f/a/b
mkdir: created directory f/a/b/c
[email protected]:~/linux/mkdir$ tree f
f
└── a
    └── b
        └── c

5,大括号:表示范围与展开:

[email protected]:~/linux/mkdir$ mkdir -pv a/{b,c,d,e,f}
mkdir: created directory a
mkdir: created directory a/b
mkdir: created directory a/c
mkdir: created directory a/d
mkdir: created directory a/e
mkdir: created directory a/f
[email protected]:~/linux/mkdir$ tree
.
└── a
    ├── b
    ├── c
    ├── d
    ├── e
    └── f
[email protected]:~/linux/mkdir$ mkdir -pv a/{1..10}
mkdir: created directory a
mkdir: created directory a/1
mkdir: created directory a/2
mkdir: created directory a/3
mkdir: created directory a/4
mkdir: created directory a/5
mkdir: created directory a/6
mkdir: created directory a/7
mkdir: created directory a/8
mkdir: created directory a/9
mkdir: created directory a/10
[email protected]:~/linux/mkdir$ tree
.
└── a
    ├── 1
    ├── 10
    ├── 2
    ├── 3
    ├── 4
    ├── 5
    ├── 6
    ├── 7
    ├── 8
    └── 9
[email protected]:~/linux/mkdir$ mkdir -pv b/{a..z}
mkdir: created directory b
mkdir: created directory b/a
mkdir: created directory b/b
mkdir: created directory b/c
mkdir: created directory b/d
mkdir: created directory b/e
mkdir: created directory b/f
mkdir: created directory b/g
mkdir: created directory b/h
mkdir: created directory b/i
mkdir: created directory b/j
mkdir: created directory b/k
mkdir: created directory b/l
mkdir: created directory b/m
mkdir: created directory b/n
mkdir: created directory b/o
mkdir: created directory b/p
mkdir: created directory b/q
mkdir: created directory b/r
mkdir: created directory b/s
mkdir: created directory b/t
mkdir: created directory b/u
mkdir: created directory b/v
mkdir: created directory b/w
mkdir: created directory b/x
mkdir: created directory b/y
mkdir: created directory b/z
[email protected]:~/linux/mkdir$ tree
.
├── a
│   ├── 1
│   ├── 10
│   ├── 2
│   ├── 3
│   ├── 4
│   ├── 5
│   ├── 6
│   ├── 7
│   ├── 8
│   └── 9
└── b
    ├── a
    ├── b
    ├── c
    ├── d
    ├── e
    ├── f
    ├── g
    ├── h
    ├── i
    ├── j
    ├── k
    ├── l
    ├── m
    ├── n
    ├── o
    ├── p
    ├── q
    ├── r
    ├── s
    ├── t
    ├── u
    ├── v
    ├── w
    ├── x
    ├── y
    └── z

 

以上是关于Linux常用基本命令( mkdir )的主要内容,如果未能解决你的问题,请参考以下文章

Linux常用基本命令( touch )

linux常用基本命令汇总

mkdir命令的使用

linux,unix常用基本命令

mkdir命令怎么使用

linux常用的基本命令