One Linux command per day (4): mkdir command

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/peida/archive/2012/10/25/2738271.html

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:

Passmkdircommand can be implemented at the specified location to create aDirName (the specified file name)the 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 folders that are created(Catalogue)cannot be associated with its parent directory(that is, the parent folder)the name of the file in the same directory cannot have the same name(Case Sensitive).

3. Command parameters:

   -m, --mode= mode, set permissions mode >  ( similar to   chmod) rwxrwxrwx &NBSP, 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:

mkdir Test1[[email protected] test]# ll total 4drwxr 2 4096 Ten:  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-x2Root root4096 Ten- -  -: theTEST1DRWXR-xr-x3Root root4096 Ten- -  -: -Test2[[email protected] test]# CD test2/[[email protected] test2]# ll total 4drwxr-xr-x2Root root4096 Ten- -  -: -Test22[[email protected] test2]#

  

Example 3: create a directory with permissions of 777

Command:

Mkdir-m 777 Test3

Output:

[Email protected] test]#mkdir-M777Test3[[email protected]alhost test]# ll Total 12drwxr-xr-x2Root root4096 Ten- -  -: theTEST1DRWXR-xr-x3Root root4096 Ten- -  -: -test2drwxrwxrwx2Root root4096 Ten- -  -: $Test3[[email protected] test]#

Description: The TEST3 permission is rwxrwxrwx

Example 4: Creating a new directory displays information

Command:

Mkdir-v test4

Output:

mkdir -v test4mkdirmkdir -vp test5/test5-1mkdir  : Directory "Test5"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 createdmkdir: Directory Created "scf/Lib "mkdir: Directory Created "scf/bin "mkdir: Directory Created "scf/Doc "mkdir: Directory Created "scf/doc/Info"mkdir: Directory Created "scf/doc/Product "mkdir: Directory Created "scf/Logs "mkdir: Directory Created "scf/logs/Info"mkdir: Directory Created "scf/logs/Product "mkdir: Directory Created "scf/Service "mkdir: Directory Created "scf/service/Deploy "mkdir: Directory Created "scf/service/deploy/Info"mkdir: Directory Created "scf/service/deploy/product "[[email protected] test]# tree SCF/SCF/|--bin|--Doc| |--Info| `--Product|--Lib|--logs| |--Info| `--Product '--Service '--Deploy|--Info            `--Product ADirectories,0Files[[email protected] test]#

One Linux command per 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.