| 短選項 | 長選項 | 含義 |
| -m <目錄屬性> | --mode <目錄屬性> | 建立目錄時同時設置目錄的權限。 |
| -p | --parents | 此選項后,可以是一個路徑名稱。 若路徑中的某些目錄尚不存在,系統將自動建立好那些尚不存在的目錄。 即一次可以建立多個目錄。 |
| -v | --verbose | 每次創建新目錄都顯示信息 |
實例1:創建一個空目錄[root@localhost test]#mkdir test1[root@localhost test]#ls -l總計 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1實例2:創建多層目錄[root@localhost test]#mkdir -p test2/test22[root@localhost test]#ls -l總計 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]# ls -l 總計 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22實例3:創建權限為777的目錄[root@localhost test]#mkdir -m 777 test3[root@localhost test]# ls -l 總計 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 說明:test3 的權限為rwxrwxrwx實例4:創建新目錄都顯示信息[root@localhost test]#mkdir -v test4mkdir: 已創建目錄 “test4” [root@localhost test]#mkdir -vp test5/test5-1mkdir: 已創建目錄 “test5” mkdir: 已創建目錄 “test5/test5-1”實例五:一個命令創建項目的目錄結構[root@localhost test]#mkdir -vp scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}mkdir: 已創建目錄 “scf” mkdir: 已創建目錄 “scf/lib” mkdir: 已創建目錄 “scf/bin” mkdir: 已創建目錄 “scf/doc” mkdir: 已創建目錄 “scf/doc/info” mkdir: 已創建目錄 “scf/doc/product” mkdir: 已創建目錄 “scf/logs” mkdir: 已創建目錄 “scf/logs/info” mkdir: 已創建目錄 “scf/logs/product” mkdir: 已創建目錄 “scf/service” mkdir: 已創建目錄 “scf/service/deploy” mkdir: 已創建目錄 “scf/service/deploy/info” mkdir: 已創建目錄 “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
創建多層目錄目錄結構:當前目錄/test1/test2mkdir -p test1/test2同等級多個目錄當前目錄/ |--test1 |--test12 |--test13mkdir {test1,test12,test13}創建多層多個目錄當前目錄/ |--test1 |--test2 |--test12 |--test13mkdir -p {test1/test2,test12,test13}當前目錄/ |--test1 |--test2 |--test3 |--test12 |--test22 |--test13mkdir -p {test1/test2/test3,test12/test22,test13}
當前目錄下,並存test1、tes1t12、test13三個目錄。 test1目錄下,存在test2。另外在test2目錄下,存在test3. test12目錄下,存在test22。
