This article introduces the use of mkdir command to create directories and subdirectories under Linux. Now we have to learn to create directories under Linux system. Under Linux, we can use the mkdir command. Mkdir is an abbreviation for "make directory".
What is mkdir?
Mkdir is a command used to create directories under Linux systems. This command is a built-in command.
Run the mkdir command
You can use it by typing mkdir directly in your console.
$ mkdir
By default, running the mkdir command without any parameters will create a directory under the current directory. The following is a reference example:
As you can see from the above picture, we have created a directory named office. When we run the mkdir command, we are in the /home/pungki directory. So this new directory office is created in the /home/pungki directory. If we use an absolute path - for example: /usr/local -, Linux will create a directory under the /usr/local directory.
When Linux finds that the directory you want to create already exists, Linux will prompt us that Linux cannot create it.
Another first condition for creating a directory is that you must have access permissions in the target path where you want to create the directory. mkdir will report this error when you are unable to obtain permissions.
Create multiple directories
We can also create multiple directories at the same time. For example, the directories we want to create include ubuntu, redhat and slackware. Then the syntax will look like this:
$ mkdir ubuntu redhat slackware
Add a directory containing subdirectories [Annotation: Create directories recursively]
When the directory you want to create contains subdirectories, you need to use the -p parameter. If mkdir cannot find the parent directory, this parameter will help create the parent directory first. For example, we want to create a directory named letter, which contains the subdirectory important. Then the syntax will look like this:
$ mkdir -p letter/important
Set access permissions
Using the -m parameter, we can set permissions for the new directory to be generated. An example is as follows:
$ mkdir -m=r-- letter
The above command will create a directory named letter and grant read-only permissions to the directory owner, user group and other users
Print the process of creating the directory Information
If we want to view information, we can use the -v parameter to achieve this. An example is as follows:
$ mkdir -v ubuntu redhat slackware
Summary
Mkdir command is also one of the most basic commands. Friends who want to learn Linux must master this command. As usual, you can type man mkdir or mkdir --help to display the mkdir man page and discuss it in more depth.
The above is the entire content of this article. I hope it will be helpful to everyone’s learning. I also hope that everyone will support the PHP Chinese website.
How to use the mkdir command to create directories and subdirectories under Linux
For more related articles about how to use the mkdir command to create directories and subdirectories under Linux, please pay attention to the PHP Chinese website!