Linux Learning one command a day (4) [mkdir command]

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:

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

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

This article is from the "Linux Personal Summary" blog, please be sure to keep this source http://xuelinux.blog.51cto.com/9927651/1708643

Linux Learning one command a day (4) [mkdir command]

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.