Special offer
popup-offers
English
+370 5 205 5502 sales@monovm.com

Create Folder in Linux Create Directory in Linux [mkdir Command]

Looking to create folder in Linux/create directory in Linux? Then this post will give you detailed insights on the mkdir command and to execute this process.

14 Sep, 21 by Antoniy Yushkevych 4 min Read

List of content you will read in this article:

Everyone who is a beginner or advanced Linux administrator somehow is looking to create folders and directories in Linux. You can create folder in Linux environments using either the command line or the file manager on your desktop. mkdir Linux command will help you to create directory in linux, which are also known as folders. So in this tutorial/blog post, We will give comprehensive knowledge and a step-by-step guide to achieving this goal through you can create folder in Linux. 

Follow the below-given steps to create a folder in Linux easily.

Step 1: In Linux, first open the terminal.

Step 2: then enter mkdir dir1 command to build a folder with the name dir1.

Let's take a closer look at certain cases and other applications. The syntax to create a directory in Linux is as follows:

mkdir folder
mkdir [option] folderName
mkdir directory

By using the ls command to list the contents of the directory, you can confirm that it was created:

ls -l 

This will show the list of all the current directories.

mkdir's -v (--verbose) option instructs it to print a message for each directory it creates.

mkdir -v folder

Result:

mkdir: created directory 'folder'

The file is generated in the current working directory when only the directory name is provided without the complete path. The latest working directory is the location where the commands are being executed. The cd command is used to modify the actual working directory.

To build a directory in a different region, you'll need to specify the parent directory's absolute or relative file direction. To construct a new directory in the /xyz directory, for example, type:

mkdir /xyz/newdirectory

You'll get a Permission denial error if you want to build a directory in a parent directory where the user doesn't have enough permissions.

mkdir /root/newdirectory

After executing the command you will get output like this: 

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

You can create a parent folder using the following command:

mkdir -p dir11/dir12
mkdir -p parent1/child1
mkdir -p pictures1/memories1

This will list all the directories present in the parent and child folder, respectively to verify it you have to follow below listed given command.

ls -l
ls -l pictures1

How to Create Directories in Linux and Assign Permissions to It

In this section, you will get how to assign/allocate permission to the created directory or folder in Linux. New directories are generated with read, write, and execute permissions by default. To set the permissions of new folder, use the -m option with directory:

mkdir -m {permissions} {dirName}
mkdir -m 777 alpha
ls -l

The sequence 777 will be inserted after the -m to construct a directory called alpha with all three forms of permissions available for all users.

How to make directory in Linux [Multiple Directories in Linux]

To construct several folders, use the command arguments to define the directories' names, separated by a space:

mkdir directory1 directory2 directory3

rmdir command/rm command to Remove the Directory/Folder in Linux

Here, we are removing a folder called directory1, so we will execute the below command:

rmdir directory1

OR

rm -rf directory1

This is all about creating a new folder in Linux by using mkdir command. Also, how you can create directories in linux with multiple files, and parent/child directories and how to remove/erase the created directory and folder permanently with rmdir or rm command.

If you feel there is any other option available in Linux to create directories and folders, Please suggest with the comment box, We will try to include your suggestion.

Keep Learning!

People Are Also Reading:

Antoniy Yushkevych

Master of word when it comes to technology, internet and privacy. I'm also your usual guy that always aims for the best result and takes a skateboard to work. If you need me, you will find me at the office's Counter-Strike championships on Fridays or at a.yushkevych@monovm.com