mkdir 功能: 創建文件夾(目錄),就和Windows下的新建文件夾的工能一樣,只是這個是在字符界面由命令生成文件夾的方式
注:
一: mkdir 可以同時創建多個目錄: mkdir a b? c? d? 表示同時創建名為a ,b ,c ,d 的四個目錄,很方便!例:
[user1@localhost 2017H]$ mkdir a b c d
[user1@localhost 2017H]$ ll
總用量 4
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 a
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 b
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 c
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 d
-rw-rw-r--. 1 user1 user1 12 2月? 11 15:49 day11.txt
[user1@localhost 2017H]$
二:同時創建多級目錄,若是在Windows界面中我們只有先建立外層目錄,再進入其中建立子目錄,而在Linux中一個命令就搞定:???? mkdir?? -p? ./hello/word??? 其中-p參數是表示如果路徑中有沒有的,就自動創建來補全。例:
[user1@localhost 2017H]$ mkdir -p ./hello/word
[user1@localhost 2017H]$ ll
總用量 4
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 a
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 b
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 c
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 d
-rw-rw-r--. 1 user1 user1 12 2月? 11 15:49 day11.txt
drwxrwxr-x. 3 user1 user1 18 2月? 11 16:14 hello
[user1@localhost 2017H]$ ll? ./hello/
總用量 0
drwxrwxr-x. 2 user1 user1 6 2月? 11 16:14 word
[user1@localhost 2017H]$
三:創建文件的同時修改文件的權限。例:創建目錄e 并設置其權限為744? ,可以先建立目錄e,然后再用chmod命令來修改其權限,但是mkdir可以一步做到,很簡潔 ? ? ? mkdir -m? 744? e
[user1@localhost 2017H]$ mkdir -m 744 e
[user1@localhost 2017H]$ ll
總用量 4
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 a
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 b
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 c
drwxrwxr-x. 2 user1 user1? 6 2月? 11 16:08 d
-rw-rw-r--. 1 user1 user1 12 2月? 11 15:49 day11.txt
drwxr--r--. 2 user1 user1? 6 2月? 11 16:20 e
drwxrwxr-x. 3 user1 user1 18 2月? 11 16:14 hello
[user1@localhost 2017H]$
四: mkdir 創建成功文件后,默認狀態下是不會輸入任何的提示信息的,但是-v參數可以使得不管創建成功與否,都會給出相應的提示 ,這樣就可以不用再創建完成后再去ls了
[user1@localhost 2017H]$ mkdir -v hhh e
mkdir: 已創建目錄 "hhh"
mkdir: 無法創建目錄"e": 文件已存在
[user1@localhost 2017H]$
參數:
DESCRIPTION
Create the DIRECTORY(ies), if they do not already exist.
Mandatory arguments to long options are mandatory for short options too.
-m, --mode=MODE
set file mode (as in chmod), not a=rwx - umask
-p, --parents
no error if existing, make parent directories as needed
-v, --verbose
print a message for each created directory
-Z? ? set? SELinux security context of each created directory to the default
type