Linux mkdir command Sorting collection

Source: Internet
Author: User

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= 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 test1

Output:

Copy the code code as follows:

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

Copy the code code as follows:

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

Copy the code code as follows:

[Email protected] test]# mkdir-m 777 Test3

[email protected] 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

[Email protected] test]#

Description

TEST3 permissions are rwxrwxrwx


Example 4: Creating a new directory displays information

Command:

Mkdir-v test4

Output:


Copy the code code as follows:

[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: The directory "Test5/test5-1" has been created

[Email protected] test]#


Example 5: A command to create a directory structure for a project

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: The directory "Scf/lib" has been created

mkdir: The directory "Scf/bin" has been created

mkdir: The directory "Scf/doc" has been created

mkdir: The directory "Scf/doc/info" has been created

mkdir: The directory "Scf/doc/product" has been created

mkdir: The directory "Scf/logs" has been created

mkdir: The directory "Scf/logs/info" has been created

mkdir: The directory "Scf/logs/product" has been created

mkdir: The directory "Scf/service" has been created

mkdir: The directory "Scf/service/deploy" has been created

mkdir: The directory "Scf/service/deploy/info" has been created

mkdir: The directory "Scf/service/deploy/product" has been created

[Email protected] test]# tree scf/

scf/

|--bin

|--doc

| |--Info

| '--product

|--Lib

|--logs

| |--Info

| '--product

'--Service

'--Deploy

|--Info

'--product

Directories, 0 files

[Email protected] test]#


Add:

This command creates the specified directory name, 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

Grammar:

mkdir [-M] [-p] Directory name

Option Description:

-M: Set access permissions on the new directory or set with the chmod command;

-P: 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;


Example of execution:

Copy the code code as follows:

$ mkdir Dira

$ ls

Dira </p> <p> $ mkdir-m 775 DIRB

$ ls-l

Drwxr-xr-x 2 xxxx users 4096 Feb 22:29 Dira

Drwxrwxr-x 2 xxxx users 4096 Feb 22:30 DIRB </p> <p> $ mkdir-p Dirc/hello

$ ls-l

Drwxr-xr-x 2 xxxx users 4096 Feb 22:29 Dira

Drwxrwxr-x 2 xxxx users 4096 Feb 22:30 DIRB

Drwxr-xr-x 3 xxxx users 4096 Feb 22:31 dirc </p> <p> $ ls dirc

Hello

In a Linux system, the function of command mkdir is to create a new folder.


Mkdir-p can create a new subdirectory in the new subdirectory.

Example:

Mkdir-p About/abc/def can create a new three directory at a recursive level.


If you want to see what mkdir has done, you can add the option "-V" to continue with the example above:

Copy the code code as follows:

MKDIR-PV About/abc/def

mkdir:created directory ' about '

mkdir:created directory ' ABOUT/ABC '

mkdir:created directory ' About/abc/def '





This article is from "Linux Rookie station" blog, please make sure to keep this source http://10930250.blog.51cto.com/10920250/1717056

Linux mkdir command Sorting collection

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.