How to use mkdir command in Linux with Examples

How to use mkdir command in Linux with Examples

In this article we are going to shows how to use mkdir command in Linux. If you want to learn about mkdir command in Linux with Examples then this post is ideal for you.

In the Linux, mkdir command is used to create new directories (folders) using command line. It is also allows the Linux users to create multiple directories at once.

Linux is an operating system, like Windows OS, iOS, and Mac OS. Linux is one of the most popular operating system on the planet, Android is also powered by Linux OS(operating system).


How to use mkdir command in Linux

In the Linux, the basic syntax of the mkdir command is show as below:

mkdir [OPTION] [DIRECTORY]

Create a New Directory

You can create a directory in Linux using the command below:

mkdir dir_name

The above command will create a new directory in the current working directory.

To verify that the directory was created or not, run the ls command :

ls -l

You can also create a directory at another location using the absolute or relative file path to the parent directory. To do that, run the command below:

mkdir /var/www/dir_name

Create Multiple Directories

mkdir command also allows you to create multiple directories at once. To do that run the command below as show below:

mkdir dir_name1 dir_name2 dir_name3

Create Parent Directories

You can also create Parent Directories with the mkdir command. To create parent directories, use the -p option with mkdir command as show below:

mkdir -p /home/studiesonline/Linux/commands/articles

The above command creates the given directory only if it doesn’t exist in your Linux system.


Set Permissions

You can use the -m (-mode) option to create a directory with specific permissions:

mkdir -m 700 dir_name

The above command will create a new directory with 700 permission. A directory with 700 permission only accessible by the user who created the directory.


Displays Message

If you want to print a message for every directory created, use -v or --verbose option with mkdir command as show below:

mkdir -v [directories]
mkdir -v dir_name1 dir_name2 dir_name3
Output
mkdir: created directory 'dir_name1'
mkdir: created directory 'dir_name2'
mkdir: created directory 'dir_name3'

That’s all.

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

Your email address will not be published. Required fields are marked *

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

Scroll to Top