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:
MKDIR  The command can be created at the specified location to filename specified ) 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 folder created directory " Span style= "Font-family:times New Roman;" >) cannot be associated with its parent directory Span style= "font-family: the song Body;" > that is, the parent folder the names of the files That is, the same directory cannot have the same name as the 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. At this point, if some directories in the path do not already exist , and with this option , the system will automatically set up those directories that do not yet 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 test1
Output:
[[Email protected] soft]# CD test
[Email protected] test]# mkdir test1
[email protected] test]# LL
Total 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1
[Email protected] test]#
Example 2: Creating multiple directories recursively
Command:
Mkdir-p test2/test22
Output:
[Email protected] test]# mkdir-p test2/test22
[email protected] test]# LL
Total 8drwxr-xr-x 2 root root 4096 10-25 17:42 test1
Drwxr-xr-x 3 root root 4096 10-25 17:44 test2
[Email protected] test]# CD test2/
[email protected] test2]# LL
Total 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22
[Email protected] test2]#
Example 3: create a directory with permissions of 777
Command:
Mkdir-m 777 Test3
Output:
[Email protected] test]# mkdir-m 777 Test3
[email protected] test]# LL
Total drwxr-xr-x 2 root root 4096 10-25 17:42 test1
Drwxr-xr-x 3 root root 4096 10-25 17:44 test2
DRWXRWXRWX 2 root root 4096 10-25 17:46 test3
[Email protected] test]#
Description
TEST3 permissions are rwxrwxrwx
Example 4: Creating a new directory displays information
Command:
Mkdir-v test4
Output:
[Email protected] test]# mkdir-v test4
mkdir: The directory "test4" has been created
[Email protected] test]# MKDIR-VP test5/test5-1
mkdir: The directory "test5" has been created
mkdir: created directory "test5/test5-1"
[Email protected] 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:
[Email protected] 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 directory "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"
[Email protected] test]# tree scf/
scf/
|--bin
|--doc
| |--Info
| '--product
|--Lib
|--logs
| |--Info
| '--product
'--Service
'--Deploy
|--Info
'--product
Directories, 0 files
[Email protected] test]#
Linux command: mkdir command explanation