Linux mkdir Commands Use the detailed _linux

Source: Internet
Author: User
Tags mkdir parent directory

The Linux mkdir command is used to create a directory of the specified name, requiring the user who created the directory to have write permission in the current directory, and the specified directory name cannot be a directory 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 named DirName (the specified file name) at the specified location. The user who is creating a folder or directory must have write permissions to the parent folder of the folder that you are creating. Also, the folder (directory) You create 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 names (case-sensitive).

3. Command parameters:
-M,--mode= mode, set permissions < mode > (similar to chmod) rather than rwxrwxrwx minus umask
-P,--parents can be a path name. At this point if some directories in the path do not already exist, plus this option, the system will automatically establish those directories that do not exist, that is, can build multiple directories;
-V,--verbose displays information each time a new directory is created
--HELP displays this help information and exits
--version output version information and exit

4. Command instance:
Instance 1: Create an empty directory
Command:
mkdir test1
Output:

Copy Code code as follows:

[Root@localhost soft]# CD test
[Root@localhost test]# mkdir test1
[Root@localhost test]# LL
Total 4drwxr-xr-x 2 root root 4096 10-25 17:42 test1
[Root@localhost test]#

Instance 2: multiple directories created recursively
command:
Mkdir-p test2/test22
Output:

Copy Code code as follows:

[Root@localhost test]# mkdir-p test2/test22
[Root@localhost 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
[Root@localhost test]# CD test2/
[Root@localhost test2]# LL
Total 4drwxr-xr-x 2 root root 4096 10-25 17:44 test22
[Root@localhost test2]#

Instance 3: Create a directory with a permission of 777
Command:
Mkdir-m 777 Test3
Output:

Copy Code code as follows:

[Root@localhost test]# mkdir-m 777 Test3
[Root@localhost test]# LL
Total 12drwxr-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
[Root@localhost test]#

Description
TEST3 permissions are rwxrwxrwx

Example 4: Creating a new directory displays information
Command:
Mkdir-v test4
Output:

Copy Code code as follows:

[Root@localhost test]# mkdir-v test4
mkdir: Directory "test4" created
[Root@localhost test]# MKDIR-VP test5/test5-1
mkdir: Directory "TEST5" created
mkdir: Directory "test5/test5-1" created
[Root@localhost test]#

Instance 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:

Copy Code code as follows:

[Root@localhost test]# MKDIR-VP Scf/{lib/,bin/,doc/{info,product},logs/{info,product},service/deploy/{info, Product}}
mkdir: Directory "SCF" created
mkdir: Directory "Scf/lib" created
mkdir: Directory "Scf/bin" created
mkdir: Directory "Scf/doc" created
mkdir: Directory "Scf/doc/info" created
mkdir: Directory "scf/doc/product" created
mkdir: Directory "Scf/logs" created
mkdir: Directory "Scf/logs/info" created
mkdir: Directory "scf/logs/product" created
mkdir: Directory "Scf/service" created
mkdir: Directory "Scf/service/deploy" created
mkdir: Directory "Scf/service/deploy/info" created
mkdir: Directory "scf/service/deploy/product" created
[Root@localhost test]# Tree scf/
scf/
|--Bin
|-|-doc
| |--Info
| '--product
|--Lib
|--Logs
| |--Info
| '--product
'--Service
'--Deploy
|--Info
'--product
Directories, 0 files
[Root@localhost test]#

The above is about the entire content of the mkdir command, the small partners understand not, in fact, as long as you know the command parameters, their combination can be

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.