iT邦幫忙

0

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 Directories
  • Create Parent Directories
  • Set permissions for a new Directory
  • Display 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:

~$ ls
data

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:

~$ ls
data  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}

~$ ls
data1  data2  data3

Method #2

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

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

Output:

~$ ls
data1  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 data
mkdir: created directory 'data'

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

~$ mkdir -v data1 data2 data3
mkdir: 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


尚未有邦友留言

立即登入留言