Linux Commands

How to Create a Directory in Linux

Directories in Linux play a crucial role in file management, organization, and system functionality. They primarily are the file folders where the users store and sort their files. All Linux distributions have a few premade directories following the Filesystem Hierarchy Standard a.k.a. FHS. It is a set of rules that is used to structure the file system directory in Linux and Unix-like systems.

Users can further make new directories to organize the files of similar types, and this is quite often an essential task. However, some users are unaware of the methods of creating a directory. If you’re one of them, this quick guide is for you. Here, we will explain the various ways to create a directory in Linux with no hassle.

How to Create a Directory in Linux

Creating directories in Linux is an easy task that you can do with the help of a simple “mkdir” command. Let’s take a look at the various use cases of the “mkdir” command.

To create a single directory, open the terminal and type in the “mkdir” command in the syntax as follows:

mkdir dir_name

 

Here, replace “dir_name” according to your requirements. For example, let’s create a directory to store the scripts.

mkdir Scripts

 

Similarly, you can create multiple directories by running the following command and separating the directory names with a space between them like the following:

mkdir dir1_name dir2_name dir3_name

 

For example, we create two directories: My_Scripts and Code_Snippets.

mkdir My_Scripts Code_Snippets

 

Please note that the previous codes create those directories in the current selected directory. However, if you want to make them directly in the parent directory, use the following command:

mkdir -p ~/Scripts

 

The “p” option is to make a directory within another directory, and the tiles(~) symbol represents the home directory.

Similarly, if you intend to create a nested directory or hierarchy of directories, use the following command:

mkdir -p dir/sub_dir

 

Conclusion

Directories are a critical component of Linux, and creating more is a fundamental task even for beginners. In this guide, we discussed the process of creating a directory, multiple directories, nested directories, and more. The given example will help you create the directories and subdirectories with no trouble.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.