mkdir:创建目录,常用参数-p。具体信息如下:
[root@oldboy ~]# man mkdir Formatting page, please wait... MKDIR(1) User Commands MKDIR(1) NAME mkdir - make directories SYNOPSIS mkdir [OPTION]... DIRECTORY... 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, --context=CTX set the SELinux security context of each created directory to CTX --help display this help and exit --version output version information and exit
参数解释:
1、-p:没有父目录时创建父目录,父目录存在不报错。
[root@oldboy ~]# ls -lrt | grep "^d" drwxr-xr-x. 2 root root 4096 Mar 28 07:32 data drwxr-xr-x 2 root root 4096 Apr 4 18:43 hello drwxr-xr-x 2 root root 4096 Apr 4 18:44 world [root@oldboy ~]# mkdir just/test/ mkdir: cannot create directory `just/test/': No such file or directory [root@oldboy ~]# mkdir -p just/test/ [root@oldboy ~]# ls -lrt | grep "^d" drwxr-xr-x. 2 root root 4096 Mar 28 07:32 data drwxr-xr-x 2 root root 4096 Apr 4 18:43 hello drwxr-xr-x 2 root root 4096 Apr 4 18:44 world drwxr-xr-x 3 root root 4096 Apr 4 18:52 just [root@oldboy ~]# ls -lrt just/test/ total 0
2、-m:创建目录时设置文件模式。
[root@oldboy ~]# mkdir hello [root@oldboy ~]# ls -ld hello/ drwxr-xr-x 2 root root 4096 Apr 4 18:56 hello/ [root@oldboy ~]# mkdir -m 644 world [root@oldboy ~]# ls -ld world/ drw-r--r-- 2 root root 4096 Apr 4 18:57 world/
用户默认创建目录权限是755,可以通过-m指定创建目录权限。
3、-v:打印每个已创建目录信息。
[root@oldboy ~]# mkdir -v hello mkdir: created directory `hello' [root@oldboy ~]# ls -ld hello/ drwxr-xr-x 2 root root 4096 Apr 4 18:43 hello/ [root@oldboy ~]# mkdir world [root@oldboy ~]# ls -ld world/ drwxr-xr-x 2 root root 4096 Apr 4 18:44 world/
4、--help:打印帮助信息并退出。
[root@oldboy ~]# mkdir --help Usage: mkdir [OPTION]... DIRECTORY... 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, --context=CTX set the SELinux security context of each created directory to CTX --help display this help and exit --version output version information and exit Report mkdir bugs to [email protected] GNU coreutils home page: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> For complete documentation, run: info coreutils 'mkdir invocation'
5、--version:打印该命令版本信息并退出。
[root@oldboy ~]# mkdir --version mkdir (GNU coreutils) 8.4 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by David MacKenzie.
实际工作中常用的-p参数,熟练掌握-p参数即可。