How to Create Directory in Linux with mkdir Command

To create new directories or folders in ubuntu Linux, For, you have to use mkdir command of Linux, suppose you want to create a new directory named my_directory, type mkdir my_directory command on the terminal and press enter, it will create my_directory in linux ubuntu system.

In this guide, we will show you how to create a directory in the Ubuntu Linux system and also can set permissions, and much more.

Here are some approaches to creating a directory in Linux Ubuntu via terminal using mkdir command:

Here is basic syntax and options of mkdir command:

mkdir [option] dir_name

Note that, The mkdir command allows users to create or make new directories in ubuntu linux system.

Approach 1: How to Create a New Directory

To create a new directory in linux ubuntu, you need to type the mkdir directory_name command on the terminal window, and after that use the ls command to check whether the directory is created or not:

mkdir Linux

If the operation is successful, the terminal returns an empty line.

To verify, use ls.

Note: To create a hidden directory, follow our guide on how to show and create hidden files in Linux.

Approach 2: Create Multiple Directories at once Linux

To create multiple directories at once in linux ubuntu, you need to type the command mkdir dir1 dir2 dir 3 in the terminal window and after that press Enter, It has created the directory at your specified location:

Suppose, you have to create a directory named folder1, folder2, folder3 etc. with a single command, for this, you have to use the mkdir folder1 folder2 folder3 command on the command line:

mkdir folder1 folder2 folder3

Approach 3: Make Parent Directories in Linux

To create parent and child directories in Linux, type mkdir with -p option on the terminal window.

Suppose, you want to create mydirtest1 as parent and mydirtest2 as child directory in Linux using terminal window, then type the command mkdir –p Linux/mydirtest1/mydirtest2 on the terminal window and press Enter:

mkdir –p Linux/mydirtest1/mydirtest2

Note that, you can use ls -R to display the recursive directory tree in linux. And Without the -p option, the terminal returns an error if one of the directories in the string does not exist.

Approach 4: Create Directory and Set Permissions Linux

While creating a directory, if you want to set any specific permissions for the directory, you have to use the -m option with the mkdir command.

By default the mkdir command sets permissions to rwx (read, write and execute) for the current user, to set directory permissions for all users, use mkdir command with -m option with user777 on a Linux terminal window, Here is an example:

mkdir –m777 DirM

To list all directories and show the permissions sets: -l

The directory with rwx permissions for all users is highlighted. As you can see on the image above, two other directories by default have rwx permission for the owner, xr for the group and x for other users.

Approach 4: Check Linux Directory & its Permissions Linux Command Line

When executing mkdir commands for creating a directory in linux, there is no feedback for successful operations. To see the details of the mkdir process, append the -v option to the terminal command.

Here are some options of mkdir command to check directory and its permission on linux command line:

Option / SyntaxDescription
mkdir directory_nameCreates a directory in the current location
mkdir {dir1,dir2,dir3,dir4}Creates multiple directories in the current location. Do not use spaces inside {}
mkdir –p directory/path/newdirCreates a directory structure with the missing parent directories (if any)
mkdir –m777 directory_nameCreates a directory and sets full read, write, execute permissions for all users
mkdir –v directory_name(s)Creates a directory in the current location

Here is the video guide on how to create a new directory and set permissions in Linux command:

Conclusion

This guide covered all commands you have learned how to create directories/folders in ubuntu Linux and how to set permission for the directory.

Recommended Posts

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

One reply to How to Create Directory in Linux with mkdir Command

  1. Hi

    Good and very useful information about mkdir command. Every option is explained well and easy to understand.

Leave a Reply

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