格式:mkdir [OPTION]… DIRECTORY…
-p: 递归创建目录
-p: 递归创建目录
不指定路径则在当前位置下创建目录
[root@localhost tmp]# pwd /tmp [root@localhost tmp]# mkdir qwe [root@localhost tmp]# tree /tmp/ /tmp/ ├── 1 │ └── 2 │ └── 3 │ └── 4 │ └── 5 ├── qwe ├── systemd-private-883a44adc3a34d5a8aaa7d4309432add-vmtoolsd.service-BFwUxk │ └── tmp └── yum_save_tx.2017-02-08.20-55.3OHjxh.yumtx 8 directories, 1 file [root@localhost tmp]#
指定路径创建目录可在任何位置执行
[root@localhost ~]# pwd /root [root@localhost ~]# mkdir /tmp/rty [root@localhost ~]# tree /tmp/ /tmp/ ├── 1 │ └── 2 │ └── 3 │ └── 4 │ └── 5 ├── qwe ├── rty ├── systemd-private-883a44adc3a34d5a8aaa7d4309432add-vmtoolsd.service-BFwUxk │ └── tmp └── yum_save_tx.2017-02-08.20-55.3OHjxh.yumtx 9 directories, 1 file [root@localhost ~]#
以递归方式逐级创建目录
[root@localhost ~]# mkdir -p /tmp/z/x/c/v/b [root@localhost ~]# tree /tmp/ /tmp/ ├── 1 │ └── 2 │ └── 3 │ └── 4 │ └── 5 ├── qwe ├── rty ├── systemd-private-883a44adc3a34d5a8aaa7d4309432add-vmtoolsd.service-BFwUxk │ └── tmp ├── yum_save_tx.2017-02-08.20-55.3OHjxh.yumtx └── z └── x └── c └── v └── b 14 directories, 1 file [root@localhost ~]#
Ubuntu系统请配合sudo使用(sudo mkdir)