Linux command : To create new directory/folder

In this post we will learn, how to create new directory in Linux system.Directory also called as folder(In Windows System). To create a new directory in Linux system we will use the command called mkdir. By using some options with mkdir command, we can do many things.

To create a directory in Linux

Use the below given command to create single directory in current path

Syntax:

mkdir dir-name

To create multiple directory in Linux

Use the below given command to create multiple directores in current path.

Syntax:

mkdir dir-name1 dir-name2 dir-name4 dir-nameN

Create directory inside existing/non existing parent directory

In case you want to create a directory inside other directory, we will use -p option with mkdir command.
Even in case parent directory do not exist,if we use -p option with mkdir command.It will create a new directory tree.

Syntax:

mkdir -p dir1/dir2/dir3/MORE-dir 

Example In this case, we have already existing directory called DIR1 and we will create new directory inside DIR1 with name sharad1 and sharad2 .
Here , the directory tree structure will be like this DIR1/sharad1/sharad2

We will use the command

mkdir -p DIR1/sharad1/sharad2

Assigning permission while creating new directory

We can assign permission while creating a new directory.For this we will use -m option with mkdir command

Syntax:

mkdir -m PERMISSION-SET directory-name

Example : We will create a directory called green with permission 400 (Read to Owner only)

test@tuxworld:~$ mkdir -m 400 green
test@tuxworld:~$ ls -ld green/
dr-------- 2 test test 4096 Mar 14 18:00 green/
test@tuxworld:~$ 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.