In this guideline, we will take a look at learning How to Use mkdir Command to Make or Create a Linux Directory? We shall examine the mkdir command, which is used to create directories, in this manual. We’ll also talk about some real-world applications of it that can assist new Linux users to feel confident using the system.
We frequently use files and folders as Linux users. While directories help us to properly organize files, files allow us to store crucial data. In addition, we frequently build a hierarchical directory structure to better arrange the information.
This essay for beginners will teach you about the mkdir command. The mkdir tool, as its name implies, creates a named directory at a specified path and enables us to build single or multiple directories at once with the required file permission.
The user must have the necessary rights on the parent directory in order to use the mkdir command; otherwise, the command will fail with the permission denied error.
What does Linux’s mkdir command do?
How to Use mkdir Command to Make or Create a Linux Directory? Users can make new folders in Linux and Unix with the mkdir command. Make Directory is referred to as mkdir. In addition to creating several directories (folders) at once, mkdir also allows you to configure permissions.
You will learn how to utilize the Linux mkdir command in this article:
- UNIX- or Linux-based system.
- Access to a command line or terminal.
- A user with the authority to add and modify directory settings.
Linux Command Syntax for mkdir
The mkdir command and the directory’s name make up the fundamental command for creating directories in Linux. The syntax of this command looks like this, and you can add options to it:
"mkdir" [option] "dir name"
Refer to the examples we give in the remaining sections of the guide to gain a better understanding of how to use mkdir.
How to Create a New Linux Directory?
Use the mkdir command and the desired name to create a directory in the terminal.
In this illustration, we made a Linux directory on the desktop. Keep in mind that options and commands in Linux are case-sensitive.
Linux mkdir
A blank line is returned by the terminal if the procedure is successful. “How to Use mkdir Command to Make or Create a Linux Directory?” Make sure by using ls.
How to Create Multiple Directories with mkdir?
With mkdir, you can create directories one at a time, but this takes time. You can create many directories simultaneously by using the mkdir command to avoid that.
To do this, specify the directory names, separated by commas, and utilize the curly brackets with mkdir:
test1, test2, and test3: mkdir
The directory names’ curly brackets should not contain any extra spaces. If you do, the following names will also have additional characters:
How to Make Parent Directories?
The -p option must be used to mkdir in order to create a structure with numerous subdirectories. By doing this, mkdir will ensure that any parent directories that are missing are added.
For instance, run the following command to create “dirtest2” in “dirtest1” of the Linux directory (i.e., Linux/dirtest1/dirtest2).
Linux/dirtest1/dirtest2 mkdir -p
To display the recursive directory tree, type ls -R.
If one of the folders in the string doesn’t exist, the terminal returns an error without the -p argument.
How to Set Permissions When Making a Directory?
How to Use mkdir Command to Make or Create a Linux Directory? By default, the mkdir command only grants the current user rwx rights.
When creating a directory, include the -m option and the user 777 to add read, write, and execute permission for all users.
Make a directory named DirM with the following permissions:
DirM mkdir -m777
To display the permissions sets and list all directories: -l
The highlighted directory has rwx permissions for all users. Two other directories, as seen in the image above, have rwx permissions by default for the owner, xr permissions for the group, and x permissions for other users.
How to Check Directory Listings?
There is no feedback when running the mkdir commands, even when they are successful. Add the -v option to the terminal command to view the details of the mkdir procedure.
To print the operation status, let’s build a Details directory inside Dir1:
You may confirm the directory was created without using the ls command by obtaining feedback from the procedure instead of running it.
mkdir Command Options and Syntax
How to Use mkdir Command to Make or Create a Linux Directory? Summary
Option / Syntax | Description |
mkdir directory name | Creates 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/newdir | Creates a directory structure with the missing parent directories (if any) |
mkdir –m777 directory name | Creates a directory and sets full read, write, and execute permissions for all users |
mkdir –v directory name(s) | Creates a directory in the current location |
Conclusion
All the commands required to create folders in Linux were covered in this guide. You now know how to use the mkdir command in Linux. It is uncomplicated and easy to use.
If you follow the steps in this article, there shouldn’t be any errors if you have the required permissions.