linux中mkdir命令使用詳解
linux mkdir 命令用來創(chuàng)建指定的名稱的目錄,要求創(chuàng)建目錄的用戶在當(dāng)前目錄中具有寫權(quán)限,并且指定的目錄名不能是當(dāng)前目錄中已有的目錄。
1.命令格式:
mkdir [選項(xiàng)] 目錄...
2.命令功能:
通過 mkdir 命令可以實(shí)現(xiàn)在指定位置創(chuàng)建以 DirName(指定的文件名)命名的文件夾或目錄。要?jiǎng)?chuàng)建文件夾或目錄的用戶必須對所創(chuàng)建的文件夾的父文件夾具有寫權(quán)限。并且,所創(chuàng)建的文件夾(目錄)不能與其父目錄(即父文件夾)中的文件名重名,即同一個(gè)目錄下不能有同名的(區(qū)分大小寫)。
3.命令參數(shù):
-m, --mode=模式,設(shè)定權(quán)限<模式> (類似 chmod),而不是 rwxrwxrwx 減 umask
-p, --parents 可以是一個(gè)路徑名稱。此時(shí)若路徑中的某些目錄尚不存在,加上此選項(xiàng)后,系統(tǒng)將自動(dòng)建立好那些尚不存在的目錄,即一次可以建立多個(gè)目錄;
-v, --verbose 每次創(chuàng)建新目錄都顯示信息
--help 顯示此幫助信息并退出
--version 輸出版本信息并退出
4.命令實(shí)例:
實(shí)例1:創(chuàng)建一個(gè)空目錄
命令:
mkdir test1
輸出:
[root@localhost soft]# cd test
[root@localhost test]# mkdir test1
[root@localhost test]# ll
總計(jì) 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1
[root@localhost test]#
實(shí)例2:遞歸創(chuàng)建多個(gè)目錄
命令:
mkdir -p test2/test22
輸出:
[root@localhost test]# mkdir -p test2/test22
[root@localhost test]# ll
總計(jì) 8drwxr-xr-x 2 root root 4096 10-25 17:42 test1
drwxr-xr-x 3 root root 4096 10-25 17:44 test2
[root@localhost test]# cd test2/
[root@localhost test2]# ll
總計(jì) 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22
[root@localhost test2]#
實(shí)例3:創(chuàng)建權(quán)限為777的目錄
命令:
mkdir -m 777 test3
輸出:
[root@localhost test]# mkdir -m 777 test3
[root@localhost test]# ll
總計(jì) 12drwxr-xr-x 2 root root 4096 10-25 17:42 test1
drwxr-xr-x 3 root root 4096 10-25 17:44 test2
drwxrwxrwx 2 root root 4096 10-25 17:46 test3
[root@localhost test]#
說明:
test3 的權(quán)限為rwxrwxrwx
實(shí)例4:創(chuàng)建新目錄都顯示信息
命令:
mkdir -v test4
輸出:
[root@localhost test]# mkdir -v test4
mkdir: 已創(chuàng)建目錄 “test4”
[root@localhost test]# mkdir -vp test5/test5-1
mkdir: 已創(chuàng)建目錄 “test5”
mkdir: 已創(chuàng)建目錄 “test5/test5-1”
[root@localhost test]#
實(shí)例五:一個(gè)命令創(chuàng)建項(xiàng)目的目錄結(jié)構(gòu)
參考:http://www.ibm.com/developerworks/cn/aix/library/au-badunixhabits.html
命令:
mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}
輸出:
[root@localhost test]# mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}
mkdir: 已創(chuàng)建目錄 “scf”
mkdir: 已創(chuàng)建目錄 “scf/lib”
mkdir: 已創(chuàng)建目錄 “scf/bin”
mkdir: 已創(chuàng)建目錄 “scf/doc”
mkdir: 已創(chuàng)建目錄 “scf/doc/info”
mkdir: 已創(chuàng)建目錄 “scf/doc/product”
mkdir: 已創(chuàng)建目錄 “scf/logs”
mkdir: 已創(chuàng)建目錄 “scf/logs/info”
mkdir: 已創(chuàng)建目錄 “scf/logs/product”
mkdir: 已創(chuàng)建目錄 “scf/service”
mkdir: 已創(chuàng)建目錄 “scf/service/deploy”
mkdir: 已創(chuàng)建目錄 “scf/service/deploy/info”
mkdir: 已創(chuàng)建目錄 “scf/service/deploy/product”
[root@localhost test]# tree scf/
scf/
|-- bin
|-- doc
| |-- info
| `-- product
|-- lib
|-- logs
| |-- info
| `-- product
`-- service
`-- deploy
|-- info
`-- product
12 directories, 0 files
[root@localhost test]#
以上就是關(guān)于mkdir命令的全部內(nèi)容了,小伙伴們理解了沒,其實(shí)只要知道命令參數(shù),自己組合即可
相關(guān)文章
php擴(kuò)展memcached和memcache的安裝配置方法
這篇文章主要介紹了php擴(kuò)展memcached和memcache的安裝配置方法,需要的朋友可以參考下2014-11-11
Linux中使用crontab命令啟用自定義定時(shí)任務(wù)實(shí)例
本篇文章主要是介紹了Linux中使用crontab命令啟用自定義定時(shí)任務(wù)實(shí)例,感興趣的小伙伴們可以參考一下。2016-10-10
Linux如何使用 MyCat 實(shí)現(xiàn) MySQL 主從讀寫分離
這篇文章主要介紹了Linux如何 MyCat 實(shí)現(xiàn) MySQL 主從讀寫分離,感興趣并且想詳情了解的小伙伴接著看下文吧2021-08-08
Linux命令學(xué)習(xí)總結(jié):詳解shutdown命令
本篇文章主要介紹了Linux命令學(xué)習(xí)總結(jié):詳解shutdown命令,該命令可以安全關(guān)閉或者重新啟動(dòng)系統(tǒng)。有興趣的可以了解一下。2016-12-12
Centos7.0安裝ceph(JEWEL)及以上版本的實(shí)例解析
這篇文章主要介紹了Centos7.0安裝ceph(JEWEL)及以上版本的實(shí)例解析,需要的朋友可以參考下2018-02-02
Linux刪文件力度過大導(dǎo)致IO占用太高的解決方案
這篇文章主要介紹了Linux刪文件力度過大導(dǎo)致IO占用太高的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-04-04

