一 mkdir
mkdir是make directories的縮寫,主要用于linux中創(chuàng)建目錄
- 創(chuàng)建的目錄不能和同級目錄中已經(jīng)存在的目錄重名
- 可以mkdir p 遞歸的同時創(chuàng)建多個目錄
1.mkdir 目錄名
[root@localhost /]# mkdir test
[root@localhost /]# ll
總用量 20
lrwxrwxrwx. 1 root root 7 4月 15 20:34 bin -> usr/bin
dr-xr-xr-x. 5 root root 4096 4月 15 20:39 boot
drwxr-xr-x. 20 root root 3200 4月 22 18:58 dev
drwxr-xr-x. 74 root root 8192 4月 22 18:58 etc
drwxr-xr-x. 2 root root 6 4月 11 2018 home
lrwxrwxrwx. 1 root root 7 4月 15 20:34 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 4月 15 20:34 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 4月 11 2018 media
drwxr-xr-x. 2 root root 6 4月 11 2018 mnt
drwxr-xr-x. 2 root root 4096 4月 20 18:57 opt
dr-xr-xr-x. 104 root root 0 4月 22 18:58 proc
dr-xr-x---. 3 root root 184 4月 21 00:58 root
drwxr-xr-x. 24 root root 660 4月 22 18:58 run
lrwxrwxrwx. 1 root root 8 4月 15 20:34 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 4月 11 2018 srv
dr-xr-xr-x. 13 root root 0 4月 22 18:58 sys
drwxr-xr-x. 2 root root 6 4月 22 19:54 test
drwxrwxrwt. 9 root root 232 4月 22 19:39 tmp
drwxr-xr-x. 18 root root 233 4月 20 05:54 usr
drwxr-xr-x. 20 root root 278 4月 20 03:03 var
2.mkdir -p 目錄一/目錄二
出現(xiàn)了test/test1/test2的嵌套
[root@localhost test]# mkdir -p test1/test2
[root@localhost test]# ll
總用量 0
drwxr-xr-x. 3 root root 19 4月 22 19:58 test1
[root@localhost test]# cd /test2
-bash: cd: /test2: 沒有那個文件或目錄
[root@localhost test]# cd test1
[root@localhost test1]# cd test2
[root@localhost test2]#
二 rmdir
rmdir是remove directories的縮寫,主要用于linux中刪除目錄
這個命令只能刪除空目錄。不能刪除非空目錄文章來源:http://www.zghlxwxcb.cn/news/detail-428008.html
1.rmdir 目錄名
[root@localhost test2]# mkdir test4
[root@localhost test2]# ll
總用量 0
drwxr-xr-x. 2 root root 6 4月 22 20:03 test
drwxr-xr-x. 2 root root 6 4月 22 20:02 test2
drwxr-xr-x. 2 root root 6 4月 22 20:03 test3
drwxr-xr-x. 2 root root 6 4月 22 20:05 test4
drwxr-xr-x. 2 root root 6 4月 22 20:02 –v
[root@localhost test2]# rmdir test4
[root@localhost test2]# ll
總用量 0
drwxr-xr-x. 2 root root 6 4月 22 20:03 test
drwxr-xr-x. 2 root root 6 4月 22 20:02 test2
drwxr-xr-x. 2 root root 6 4月 22 20:03 test3
drwxr-xr-x. 2 root root 6 4月 22 20:02 –v
2.刪除非空目錄時失敗
[root@localhost test]# ll
總用量 0
drwxr-xr-x. 2 root root 6 4月 22 20:12 edu
drwxr-xr-x. 3 root root 19 4月 22 19:58 test1
[root@localhost test]# tree
.
├── edu
└── test1
└── test2
├── test
├── test2
├── test3
└── \342\200\223v
7 directories, 0 files
[root@localhost test]# rmdir test1
rmdir: 刪除 "test1" 失敗: 目錄非空
3. rmkdir -p 目錄1/目錄2
示范:文章來源地址http://www.zghlxwxcb.cn/news/detail-428008.html
rmdir -p edu/teacher/
[root@localhost test]# cd edu
[root@localhost edu]# mkdir teacher
[root@localhost edu]# tree
.
└── teacher
1 directory, 0 files
[root@localhost edu]# cd ../
[root@localhost test]# tree
.
├── edu
│ └── teacher
└── test1
└── test2
├── test
├── test2
├── test3
└── \342\200\223v
8 directories, 0 files
[root@localhost test]# rmdir -p /edu/teacher
rmdir: 刪除目錄 "/" 失敗: 設(shè)備或資源忙
[root@localhost test]# rmdir -p edu/teacher/
[root@localhost test]# ll
總用量 0
drwxr-xr-x. 3 root root 19 4月 22 19:58 test1
[root@localhost test]# tree
.
└── test1
└── test2
├── test
├── test2
├── test3
└── \342\200\223v
6 directories, 0 files
[root@localhost test]#
到了這里,關(guān)于linux命令----- mkdir與rmdir的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!