mkdir Command : How to Create a Directory in Linux

Today we will learn how to create a directory in Linux operating system using mkdir command.

Let’s get started.

The mkdir command is derived from an ordinary word and that is Make Directory.

What we call a folder in Microsoft Windows is called a directory in Linux.

Features of mkdir Command

Make new DirectoriesCreate Parent DirectoriesSet permissions for a new DirectoryDisplay Output Message

You must follow the syntax given below to use the mkdir command.

mkdir [OPTION]... DIRECTORY...

1. Create a New Directory

To create new directory type the following command.

~$ mkdir data

Output:

~$ lsdata

2. Create Multiple Directories

To create multiple directories, pass the names of the directories to mkdir command.

In this example, I am creating three directories named data, data1, and data2.

~$ mkdir data data1 data2

Output:

~$ lsdata  data1  data2

There are other methods by which we can create multiple directories.

Method #1

You can specify the names of directories inside a curly bracket. Make sure that the directory names should be separated by commas.

Example:

~$ mkdir {data1,data2,data3}

~$ lsdata1  data2  data3

Method #2

You can also use the following method to create multiple directories.

~$ mkdir data{1,2,3,4,5}

Output:

~$ lsdata1  data2  data3  data4  data5

3. Display Output Message for each created Directory

To display the output message for each created directory pass the -v option to mkdir.

Let’s take some examples:

Task #1 Create a directory named data.

~$ mkdir -v datamkdir: created directory 'data'

Task #2 Create multiple directories named data1, data2, and data3.

~$ mkdir -v data1 data2 data3mkdir: created directory 'data1'mkdir: created directory 'data2'mkdir: created directory 'data3'

You can also use the long option --verbose.

~$ mkdir --verbose data

Read Complete Story Here


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章