YouTube Icon

Code Playground.

How to Create Directories in Linux (mkdir Command)

CFG

How to Create Directories in Linux (mkdir Command)

In Linux frameworks, you can make new indexes either from the order line or with the assistance of your work area's document administrator. The order that permits you to make indexes (otherwise called organizers) is mkdir. 

This instructional exercise covers the nuts and bolts of utilizing the mkdir order, including ordinary models. 

Linux mkdir Command Syntax

The linguistic structure for the mkdir order is as per the following: 

mkdir [OPTION] [DIRECTORY]

The order takes at least one index names as its contentions. 

How to Create a New Directory

To make a registry in Linux pass the name of the catalog as the contention to the mkdir order. For instance, to make another registry newdir you would run the accompanying order: 

mkdir newdir

You can check that the catalog was made by posting the substance utilizing the ls order : 

ls -l
drwxrwxr-x 2 username username 4096 Jan 20 03:39 newdir

While giving just the registry name, without the full way, it is made in the current working index. 

The current working registry is the catalog from which you are running the orders. To change the current working registry, utilize the album order. 

To make a catalog in another area you'll have to give the supreme or relative document way to the parent index. For instance, to make another index in the/tmp catalog you would type: 

mkdir /tmp/newdir

In the event that you attempt to make a catalog in a parent index where the client doesn't have adequate authorizations you will get Permission denied blunder: 

mkdir /root/newdir
mkdir: cannot create directory '/root/newdir': Permission denied

The - v (- - verbose) alternative advises mkdir to print a directive for each made registry. 

How to Create Parent Directories

A parent registry is a catalog that is over another index in the index tree. To make parent registries, utilize the - p choice. 

Suppose you need to make a catalog/home/linuxize/Music/Rock/Gothic: 

mkdir /home/linuxize/Music/Rock/Gothic

In the event that any of the parent catalogs don't exist you will get a blunder as demonstrated as follows: 

mkdir: cannot create directory '/home/linuxize/Music/Rock/Gothic': No such file or directory

Rather than making the missing guardian registries individually, conjure the mkdir order with the - p choice: 

mkdir -p /home/linuxize/Music/Rock/Gothic

When the - p choice is utilized, the order makes the catalog just on the off chance that it doesn't exist. 

In the event that you attempt to make a registry that as of now exists and the - p alternative isn't given, mkdir will print File exists mistake: 

mkdir newdir
mkdir: cannot create directory 'newdir': File exists

How to Set Permissions when Creating a Directory

To make a registry with explicit authorizations, utilize the - m (- mode) choice. The language structure for allotting authorizations is equivalent to with the chmod order. 

In the accompanying model, we're making another registry with 700 authorizations, which implies that lone the client who made the catalog will have the option to get to it: 

mkdir -m 700 newdir

When the - m choice isn't utilized, the recently made catalogs typically have either 775 or 755 authorizations, contingent upon the umask esteem. 

How to Create Multiple Directories

To make numerous catalogs, determine the indexes' names as the order contentions, isolated by space: 

mkdir dir1 dir2 dir3

The mkdir order additionally permits you to make an intricate catalog tree with one order: 

mkdir -p Music/{Jazz/Blues,Folk,Disco,Rock/{Gothic,Punk,Progressive},Classical/Baroque/Early}

The order above makes the accompanying catalog tree : 

Music/
|-- Classical
|   `-- Baroque
|       `-- Early
|-- Disco
|-- Folk
|-- Jazz
|   `-- Blues
`-- Rock
    |-- Gothic
    |-- Progressive
    `-- Punk

Conclusion 

The mkdir order in Linux is utilized to make new catalogs. 

For more data about mkdir, visit the mkdir man page . 

In the event that you have questions, don't hesitate to leave a remark underneath.




CFG