The linux mkdir command is used to creates the specified Name of directory, requires the user who created the directory to have write permissions in the current directory, and the specified directory name cannot be a directory that is already in the current directory .
1. Command format:
mkdir [ options ] directory ...
2. Command function:
Passmkdircommand can be implemented at the specified location to create aDirName (the specified file name)the named folder or directory. The user who creates the folder or directory must have write permissions to the parent folder of the folder that is created. Also, the folders that are created(Catalogue)cannot be associated with its parent directory(that is, the parent folder)the name of the file in the same directory cannot have the same name(Case Sensitive).
3. Command parameters:
- m,--mode= mode, set permissions < mode > (similar to chmod) instead of rwxrwxrwx minus umask
-P,--parents can be a path name. In this case, if some directories in the path do not already exist, and with this option, the system will automatically establish those that do not already exist, that is, multiple directories can be established at one time;
-V,--verbose displays information each time a new directory is created
--help Display This help message and exit
--version output version information and exit
4. Command instance:
Example 1: Create an empty directory
Command:
mkdir text
Output:
[begin] 2015/12/23 0:06:25[[email protected] ~]# &NBSP;LLTOTAL&NBSP;60-RW-------. 1 root root 3328 Dec 19 05:42 Anaconda-ks.cfg-rw-r--r--. 1 root root 39935 Dec 19 05:42 Install.log-rw-r--r--. 1 root root 9154 Dec 19 05:39 install.log.syslog[[email protected] ~]# mkdir text[[email protected] ~]# LLTOTAL&NBSP;64-RW-------. 1 root root 3328 Dec 19 05:42 Anaconda-ks.cfg-rw-r--r--. 1 root root 39935 Dec 19 05:42 Install.log-rw-r--r--. 1 root root 9154 Dec 19 05:39 install.log.syslogdrwxr-xr-x 2 root root 4096 dec 22 16:07 text[end] 2015/12/23 0:07:12
Example 2: recursively Create multiple directories
Command:
mkdir-p/root/text/text1/text2
Output:
[begin] 2015/12/23 0:09:33[[email protected] ~]# [[email protected] ~]# mkdir -p /root/text/text1/text2[[email protected] ~]# cd text/[[email protected] text]# tree.└── text1 └── text22 directories, 0 files[[email protected] text]# cd text1/[[email protected] text1]# cd text2/[[email protected] text2]# pwd/ root/text/text1/text2[end] 2015/12/23 0:10:09
Example 3: Create a directory with permissions of 777
Command:
mkdir-m 777 Text3
[BEGIN] 2015/12/23 0:11:05[[email protected] text2]# [[email protected] text2]# mkdir-m 777 Text3[[email protected] Text2 ]# lltotal 4drwxrwxrwx 2 root root 4096 Dec 16:11 Text3[end] 2015/12/23 0:11:13
Description
Text3 permissions are rwxrwxrwx
Example 4: Creating a new directory displays information
Command:
mkdir-v Text4
Output:
[BEGIN] 2015/12/23 0:13:00[[email protected] text2]# [[email protected] text2]# CD Text3/[[email protected] text3]# mkdir -V text4mkdir:created directory ' Text4 ' [[email protected] text3]# Lltotal 4drwxr-xr-x 2 root root 4096 Dec 16:13 Text4 [END] 2015/12/23 0:13:37
Example Five: a command to create a directory structure for a project
Reference: http://www.ibm.com/developerworks/cn/aix/library/au-badunixhabits.html
Command:
MKDIR-VP Text4/{a/,b/,c/{d1,d2},d/{e1,e2},e/f/{g1,g2}}
[begin] 2015/12/23 0:18:44[[email protected] text3]# [[email protected] Text3]# cd text4/[[email protected] text4]# mkdir -vp text4/{a/,b/,c/{d1,d2 },d/{e1,e2},e/f/{g1,g2}}mkdir: created directory ' Text4 ' mkdir: created directory ' text4/a/' mkdir: created directory ' text4/b/' mkdir: created directory ' Text4/c ' mkdir: created directory ' text4/c/d1 ' mkdir: created directory ' text4/c/ D2 ' mkdir: created directory ' text4/d ' mkdir: created directory ' text4/d/e1 ' mkdir: created directory ' text4/d/e2 ' mkdir: created directory ' text4/e ' mkdir: created directory ' text4/e/f ' mkdir: created directory ' text4/e/f/g1 ' mkdir: created directory ' Text4/e/f/g2 ' [[email protected] text4]# tree.└── text4 ├── a&nbSp; ├── b ├── c │?? ├── d1 │?? └── d2 ├── d │?? ├── e1 │?? └── e2 └── e └── f ├── g1 └── g213 directories, 0 files[END] 2015/12/23 0:19:02
A Linux mkdir command every day