Use the mkdir command to create directories and subdirectories under Linux

Source: Internet
Author: User
Tags create directory


What is mkdir?

Mkdir is a command to create a directory under a Linux system. This command is part of the built-in command.

Run the mkdir command

You can use it by typing mkdir directly in your console.

 
   
  
  1. $ mkdir

By default, running the mkdir command without any parameters creates a directory under the current directory. Here is a reference example:

mkdir command

from the See, we created the name  office   The directory. When we run the mkdir command, we are located in  /home/pungki   directory. So this new directory Office  directory.  -For example: /usr/local  -, then Linux will  /usr/local directory.

When Linux discovers that the directory you want to create already exists, Linux will prompt us that Linux cannot create it.

mkdir directory exist

Another prerequisite for creating a directory is that you must have access to the destination path where you want to create the directory . MKDIR will report this error when you are unable to get permission.

mkdir Permission denied

Create multiple Catalogs

We can also create multiple directories at the same time. For example, the directory we are creating has  ubuntu, Redhat, and Slackware . So the syntax would look like this:

 
   
  
  1. $ mkdir Ubuntu Redhat slackware

Create multiple directories

To add a directory that contains subdirectories [Note: Create a directory recursively]

When you want to create a directory that contains subdirectories, you need to use the-p parameter. If mkdir cannot find the parent directory, this parameter first helps to create the parent directory. For example, we want to create a directory named  letter  , which contains subdirectories in its directory  important . So the syntax would look like this:

  
 
    1. $ mkdir Span class= "pun" style= "Word-wrap:break-word; Color:rgb (255,255,255) ">- p Letter / important

mkdir sub-directory

Set access Permissions

With the- m parameter, we can set permissions for the new directory that will be generated. Examples are as follows:

  
 
    1. $ mkdir Span class= "pun" style= "Word-wrap:break-word; Color:rgb (255,255,255) ">- m = r -- letter

The above command creates a directory named letter, giving read-only permissions to directory owners, user groups, and other users for the directory

mkdir Set Privilege

Print process information for creating a directory

If we want to see the information, we can use the- v parameter to implement it. Examples are as follows:

 
   
  
  1. $ mkdir Span class= "pun" style= "Word-wrap:break-word; Color:rgb (255,255,255) ">- v Ubuntu Redhat slackware

mkdir verbose

Summarize

The Mkdir command also belongs to the most basic command, which must be mastered for a friend who wants to learn Linux. As usual, you can type man mkdir or mkdir--help to show mkdir's manual page and more in-depth discussion.

Finally, I enclose the summary of Brother Bird:

[Email protected] ~]#mkdir [-mp] Directory nameOptions and Parameters:-M: Configuration file Permissions Oh! Direct configuration, do not need to look at the default permissions (umask) of the face ~-p: help you directly to the desired directory (including the top level of the directory) to be handed back to create! Example: Please try to create several new directories under/TMP to see:[Email protected] ~]#cd/tmp[Email protected] tmp]#mkdir Test    <== Creating a new directory for test[Email protected] tmp]#mkdir test1/test2/test3/test4Mkdir:cannot Create directory ' TEST1/TEST2/TEST3/TEST4 ': No such file or directory<== No way to create this directory directly! [Email protected] tmp]#mkdir-p Test1/test2/test3/test4# Add this-p option to help you create multi-level catalogs! Example: Creating a directory with permissions of Rwx--x--x[Email protected] tmp]#mkdir-m 711 Test2[Email protected] tmp]#ls-lDrwxr-xr-x 3 root root 4096 Jul 12:50 testdrwxr-xr-x 3 root root 4096 Jul 12:53 test1Drwx--x--x2 root root 4096 Jul 12:54 test2# Take a closer look at the permissions section above, and if you do not add-m to force the configuration property, the system uses the default property. # So what's your default property? This will be through the umask of the below to understand Oh! ^_^

via:http://linoxide.com/linux-command/linux-mkdir-command/

Use the mkdir command to create directories and subdirectories under Linux

Related Article

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.