Common Linux commands in work: mkdir command

Source: Internet
Author: User
Tags create directory parent directory

This article link: http://www.cnblogs.com/MartinChentf/p/6076075.html (reproduced please specify the source)

In a Linux system, the mkdir command is used to create a directory or a cascading directory.

1. Command format

mkdir [Options] Directory name

2. Command options

-m=Mode

Specify access permissions for the directory, similar to chmod.

-P If the directory already exists, there is no error message. If the parent directory does not exist, the parent directory will be created. This option is commonly used to create cascading catalogs.

-V Displays the prompt information for each directory.

3. Example

Example 1: Create the Baklog directory in the current directory.

/home/dodv81>umask
0002
/home/dodv81>mkdir baklog/home/dodv81>lldrwxrwxr-x 2 4096: baklog/home/dodv81>mkdir baklog mkdir: Cannot create directory ' Baklog': File exists

The mkdir command does not have any options to create the directory by default in the current directory, and the default permission for the directory is 777-umask. An error will be prompted if the directory already exists.

Example 2: Create multiple directories.

/home/dodv81/baklog>mkdir  cep dod testlog/home/dodv81/baklog>lsCEP  DoD  Testlog

Or, multiple directories are enclosed in curly braces ({}) and separated by commas.

/home/dodv81/baklog>mkdir  {cep,dod,testlog}/home/dodv81/baklog>ls CEP  DoD  testlog

There can be no whitespace before or after the comma, otherwise the following directory will be created:

/home/dodv81/baklog>mkdir  {CEP, DOD, testlog}/home/dodv81/baklog>ls{ CEP,  DoD,  testlog}

Example 3: Create a cascading directory. Subdirectories in the same directory are enclosed in curly braces and separated by commas.

/home/dodv81>mkdir -P baklog/{bin,lib,lig/{Cep,dod,testlog}}/home/dodv81>ls -R baklog/baklog/: Bin  lib  ligbaklog/bin:baklog/lib:baklog/ lig:cep  dod  testlogbaklog/lig/cep:baklog/lig/dod:baklog/lig/testlog :

Example 4: Specify permissions for the directory, and the specified permissions are mode-umask. For example, Mode=rx, the final permission is 555-2=554, which is rw-rw-r--.

/home/dodv81/baklog/bin> mkdir -m= R A --read-only
/home/dodv81/baklog/bin> mkdir -m=w B --Write only/home/dodv81/baklog/bin> mkdir -m= RW C --Read and write/home/dodv81/baklog/bin> mkdir -m= Rx D --read executable/home/dodv81/baklog/bin> mkdir -m= rwx E --Read and write executable/home/dodv81/baklog/bin>Lltotal -Dr--r--r--2dodv81 dodv814096Nov - at: -AD-W--W----2dodv81 dodv814096Nov - at: -BDRW-rw-r--2dodv81 dodv814096Nov - at: -CDR-xr-xr-x2dodv81 dodv814096Nov - at: -DDRWXRWXR-X2dodv81 dodv814096Nov - at: theE

Example 5: Viewing process information for creating a directory

/home/dodv81>mkdir -vp baklog/{bin,lib,lig/{cep,dod,testlog}}mkdir: Created directory ' Baklog'mkdir: Created directory ' Baklog/bin'mkdir: Created Directory ' Baklog/lib'mkdir: Created directory ' Baklog/lig'mkdir: Created Directory ' baklog/lig/cep'mkdir: Created directory ' Baklog/lig/dod'mkdir : Created directory ' Baklog/lig/testlog'

Common Linux commands at work: directory

Common Linux commands in work: 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.