欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

Linux常用基本命令( mkdir )

程序员文章站 2023-02-19 13:47:25
mkdir: 作用:创建目录( make directories ) 命令格式: make [option] 目录 1,创建目录, 当目录存在时,再次创建会提示文件已经存在 2,可以一次性创建多个目录 3,当一个目录的上级目录不存在时候,需要用-p 递归创建 4,-v 输出创建目录过程的详细信息 5 ......

mkdir:

作用:创建目录( make directories )

命令格式: make [option] 目录

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

ghostwu@dev:~/linux/mkdir$ ls
ghostwu@dev:~/linux/mkdir$ tree -d
.

0 directories
ghostwu@dev:~/linux/mkdir$ mkdir a
ghostwu@dev:~/linux/mkdir$ ls
a
ghostwu@dev:~/linux/mkdir$ mkdir a
mkdir: cannot create directory ‘a’: File exists

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

ghostwu@dev:~/linux/mkdir$ ls
a
ghostwu@dev:~/linux/mkdir$ mkdir b c d
ghostwu@dev:~/linux/mkdir$ ls
a  b  c  d

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

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

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

ghostwu@dev:~/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'
ghostwu@dev:~/linux/mkdir$ tree f
f
└── a
    └── b
        └── c

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

ghostwu@dev:~/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'
ghostwu@dev:~/linux/mkdir$ tree
.
└── a
    ├── b
    ├── c
    ├── d
    ├── e
    └── f
ghostwu@dev:~/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'
ghostwu@dev:~/linux/mkdir$ tree
.
└── a
    ├── 1
    ├── 10
    ├── 2
    ├── 3
    ├── 4
    ├── 5
    ├── 6
    ├── 7
    ├── 8
    └── 9
ghostwu@dev:~/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'
ghostwu@dev:~/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