The Linux mkdir command is used to create a directory of the specified name, requiring 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:
The mkdir command enables you to create a folder or directory that is named DirName (the specified file name) at the specified location. The user who creates the folder or directory must have write permissions to the parent folder of the folder that is created. Also, the folder (directory) You create cannot have the same name as the filename in its parent directory (that is, the parent folder), that is, the same directory cannot have the same name (case sensitive).
3. Command parameters:
-M, --Mode= pattern, 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 displays this information and exits
--version output information and exit
4. Command instance:
Example 1: Create an empty directory
Command:
mkdir test1
Output:
[root@localhost soft]# CD test
[root@localhost test]# mkdir test1
[root@localhost test]# ll
Total 4drwxr-XR-x 2 root 4096 £ º test1
[root@localhost test]#
Example 2: Creating Multiple directories recursively
Command:
Mkdir-p test2/test22
Output:
[root@localhost test]# mkdir-p test2/test22
[root@localhost test]# ll
Total &NBSP; 8drwxr - XR - x &NBSP; 2 &NBSP; root&NBSP; root &NBSP; 4096 &NBSP; - : class= "Apple-converted-space" >&NBSP; test1
DRWXR-XR-x 3 root root 4096 : test2
[root@localhost test]# cd test2/
[root@localhost test2]# ll
Total 4drwxr-XR-x 2 root 4096 Ten- : test22
[root@localhost test2]#
Example 3: Create a directory with permissions of 777
Command:
Mkdir-m 777 Test3
Output:
[root@localhost test]# mkdir-m 777 test3
[root@localhost test]# ll
Total &NBSP; 12drwxr - XR - x &NBSP; 2 &NBSP; Root&NBSP; root &NBSP; 4096 &NBSP; - + : $ &NBSP; test1
drwxr - XR - x &NBSP; 3 &NBSP; root&NBSP; root &NBSP; 4096 &NBSP; - &NBSP; : $ &NBSP; test2
drwxrwxrwx 2 root root 4096 :46 test3
[root@localhost test]#
Description
TEST3 permissions are rwxrwxrwx
Example 4: Creating a new directory displays information
Command:
Mkdir-v test4
Output:
[root@localhost test]# mkdir-v test4
mkdir: the directory "test4" has been created
[root@localhost test]# MKDIR-VP test5/test5-1
mkdir: the directory "test5" has been created
mkdir: created directory "test5/test5-1"
[root@localhost test]#
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 Scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info,product}}
Output:
[root@localhost test]# MKDIR-VP Scf/{lib/,bin/,doc/{info,product},logs/{info,product} , service/deploy/{info,product}}
mkdir: the directory "SCF" has been created
mkdir: created directory "scf/Lib"
mkdir: created directory "scf/bin"
mkdir: created directory "scf/doc"
mkdir: created directory "scf/doc/info"
mkdir: created catalog "SCF/doc/product"
mkdir: created directory "SCF/logs"
mkdir: created directory "SCF/logs/info"
mkdir: created directory "SCF/logs/product"
mkdir: created directory "SCF/Service"
mkdir: created directory "SCF/service/deploy"
mkdir: created directory "SCF/service/Deploy/info"
mkdir: created directory "SCF/service/deploy/product"
[root@localhost test]# tree scf/
SCF/
|-- bin
|-- Doc
| |-- Info
| '-- product
|-- Lib
|-- Logs
| |-- Info
| '-- product
'-- service
'-- deploy
|-- Info
'-- product
directories, 0 files
[root@localhost test]#
One Linux command per day (4): mkdir