One Linux Command every day (4): mkdir, the linux Command mkdir
The linux mkdir command is used to create a directory with the specified name. The user who creates the directory must have the write permission in the current directory, and the specified directory name cannot be an existing directory in the current directory.
1. Command Format:
Mkdir [Option] Directory...
2. command functions:
The mkdir command can be used to create a folder or directory named by DirName at a specified position. To create a folder or directory, you must have the write permission on the parent folder of the created folder. In addition, the created folder (directory) cannot have the same name as the file name 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 = mode, set the permission <mode> (similar to chmod), rather than rwxrwxrwx minus umask
-P, -- parents can be a path name. If some directories in the path do not exist, after this option is added, the system will automatically create those directories that do not exist, that is, multiple directories can be created at a time;
-V, -- verbose displays information every time a new directory is created
-- Help: displays the help information and exits.
-- Version: Output version information and exit
4. Command instance:
Instance 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 10-25 test1
[Root @ localhost test] #
Example 2: recursively create multiple directories
Command:
Mkdir-p test2/test22
Output:
[Root @ localhost test] # mkdir-p test2/test22
[Root @ localhost test] # ll
Total 8drwxr-xr-x 2 root 4096 10-25 test1
Drwxr-xr-x 3 root 4096 10-25 test2
[Root @ localhost test] # cd test2/
[Root @ localhost test2] # ll
Total 4drwxr-xr-x 2 root 4096 10-25 test22
[Root @ localhost test2] #
Instance 3: create a directory with the 777 permission
Command:
Mkdir-m 777 test3
Output:
[Root @ localhost test] # mkdir-m 777 test3
[Root @ localhost test] # ll
Total 12drwxr-xr-x 2 root 4096 10-25 test1
Drwxr-xr-x 3 root 4096 10-25 test2
Drwxrwxrwx 2 root 4096 10-25 test3
[Root @ localhost test] #
Note:
Test3 permission: rwxrwxrwx
Instance 4: information is displayed when a new directory is created.
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: Directory test5/test5-1 created"
[Root @ localhost test] #
Example 5: A command is used to create the directory structure of 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 "scf" directory has been created"
Mkdir: You have created the "scf/lib" directory"
Mkdir: You have created the "scf/bin" directory"
Mkdir: the "scf/doc" directory has been created"
Mkdir: the "scf/doc/info" directory has been created"
Mkdir: the "scf/doc/product" directory has been created"
Mkdir: You have created the "scf/logs" directory"
Mkdir: You have created the "scf/logs/info" directory"
Mkdir: You have created the "scf/logs/product" directory"
Mkdir: the "scf/service" directory has been created"
Mkdir: You have created the "scf/service/deploy" directory"
Mkdir: the directory "scf/service/deploy/info" has been created"
Mkdir: the directory "scf/service/deploy/product" has been created"
[Root @ localhost test] # tree scf/
Scf/
| -- Bin
| -- Doc
| -- Info
| '-- Product
| -- Lib
| -- Logs
| -- Info
| '-- Product
'-- Service
'-- Deploy
| -- Info
'-- Product
12 directories, 0 files
[Root @ localhost test] #
Compilation: peida
Link: http://www.cnblogs.com/peida/archive/2012/10/25/2738271.html
The free course for Linux cloud computing started in January,5 days freeO & M dry goods content free of charge,Click the end of the article"Read original"Free O & M courses!Speed to grab ~~~~
PS: Check out the free gift package provided by xiaobian ~
Benefits | more than 10 thousand sets of PPT templates for free! Unconditional receipt!
Free | more than 1000 sets of resume templates are offered free of charge, and a resume creation tutorial is provided!
Free of charge | the "Shell script 100 cases" ebook is free of charge and must be used for O & M ~
Click 【Read original], Free to listen to five days of Linux O & M Dry Goods sharing courses, hot discussion, come to grab!