Use the mkdir command to create directories and subdirectories under Linux
now that we've listed the entries in the directory with the LS command, we're going to learn how to create a directory under a Linux system. Under Linux, we can use the mkdir command. MKDIR is the acronym for Make directory.
What is mkdir?
Mkdir is a command to create a directory under a Linux system. This command is part of the 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 creates a directory under the current directory. Here is a reference example:
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893601.png "alt=" mkdir command "width=" 705 "vspace=" 5 "style=" border:0px; "/>
As we've seen, we've created a directory called office . When we run the mkdir command, we are in the /home/pungki directory. So this new directory office is created under the/home/pungki directory. If we use absolute paths -for example:/usr/local -, then Linux will create a directory under the /usr/local directory.
When Linux discovers that the directory you want to create already exists, Linux will prompt us that Linux cannot create it.
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893602.png "alt=" mkdir directory Exist " Width= "705" vspace= "5" style= "border:0px;"/>
Another prerequisite for creating a directory is that you must have access to the destination path where you want to create the directory . MKDIR will report this error when you are unable to get permission.
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893603.png "alt=" mkdir Permission denied "Width=" 705 "vspace=" 5 "style=" border:0px; "/>
Create multiple Catalogs
We can also create multiple directories at the same time. For example, the directory we are creating is Ubuntu, RedHat and Slackware. Then the syntax would look like this:
$ mkdir Ubuntu Redhat Slackware
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893604.png "alt=" Create multiple Directories "width=" 705 "vspace=" 5 "style=" border:0px; "/>
To add a directory that contains subdirectories [Note: Create a directory recursively]
When you want to create a directory that contains subdirectories, you need to use the-p parameter. If mkdir cannot find the parent directory, this parameter first helps to create the parent directory. For example, we want to create a directory named letter, which contains subdirectories importantin its directory. Then the syntax would look like this:
$ mkdir - P Letter / Important
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893605.png "alt=" mkdir sub-directory " Width= "705" vspace= "5" style= "border:0px;"/>
Set access Permissions
With the- m parameter, we can set permissions for the new directory that will be generated. Examples are as follows:
$ mkdir - m = R -- Letter
The above command creates a directory named letter, giving read-only permissions to directory owners, user groups, and other users for the directory
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893606.png "alt=" mkdir set privilege " Width= "705" vspace= "5" style= "border:0px;"/>
Print process information for creating a directory
If we want to see the information, we can use the- v parameter to implement it. Examples are as follows:
$ mkdir - v Ubuntu redhat Slackware
650) this.width=650; "src=" Http://www.linuxidc.com/upload/2014_03/140319121893607.png "alt=" mkdir verbose "width=" 705 "vspace=" 5 "style=" border:0px; "/>
Summarize
The Mkdir command also belongs to the most basic command, which must be mastered for a friend who wants to learn Linux. As usual, you can type man mkdir or mkdir--help to show mkdir's manual page and more in-depth discussion.
rmdir command [only suitable for deleting empty directories]
function is to delete an empty directory.
- v Options
Prompt to delete operation succeeded:
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8D/93/wKiom1iibqCCWF8PAACpOjcS4L0678.jpg-wh_500x0-wm_ 3-wmp_4-s_4235897931.jpg "title=" 1.jpg "alt=" Wkiom1iibqccwf8paacpojcs4l0678.jpg-wh_50 "/>
- P Options
If a directory and its subdirectories are empty, and the-p option is used when deleting the most subdirectories, the related directories are deleted.
:
650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M01/8D/93/wKiom1iibqnzkKO8AAE4PAXouHQ298.jpg-wh_500x0-wm_ 3-wmp_4-s_3731340412.jpg "title=" 2.jpg "alt=" Wkiom1iibqnzkko8aae4paxouhq298.jpg-wh_50 "/>
RM command [more for deleting empty directories/files]
The function is to delete files or directories. If the directory is not empty, use the RM command to configure the necessary options to remove the non-empty directory.
- v Options
You can delete one or more files directly, and use the-v option to give hints. :
650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M00/8D/91/wKioL1iibrKzuIB3AADDk6RcLHE680.jpg-wh_500x0-wm_ 3-wmp_4-s_2890333051.jpg "title=" 3.jpg "alt=" Wkiol1iibrkzuib3aaddk6rclhe680.jpg-wh_50 "/>
Of course, you can also use wildcards to specify which files to delete. For example, remove the file name with the C end and the extension to the files named DiC:
650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/8D/93/wKiom1iibrzSJeK1AADui_SEm04888.jpg-wh_500x0-wm_ 3-wmp_4-s_4214533281.jpg "title=" 4.jpg "alt=" Wkiom1iibrzsjek1aadui_sem04888.jpg-wh_50 "/>
- F Options
Regardless of whether the directory being deleted is present, it is executed without prompting. Assuming that/mydir/noedir does not exist at all, but is specified as the directory at the time of deletion, use the-f option to not prompt the directory for errors that do not exist. :
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M02/8D/93/wKiom1iibsWBlFzxAAC57Zi2ToA115.jpg-wh_500x0-wm_ 3-wmp_4-s_4253302292.jpg "title=" 5.jpg "alt=" Wkiom1iibswblfzxaac57zi2toa115.jpg-wh_50 "/>
- R Options
This option implements deleting all files under the specified directory. :
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/8D/91/wKioL1iibtHhfCf7AAGBlM_PvXk373.jpg-wh_500x0-wm_ 3-wmp_4-s_2255342914.jpg "title=" 6.jpg "alt=" Wkiol1iibthhfcf7aagblm_pvxk373.jpg-wh_50 "/>
● Combination Options
If you want to delete a non-empty directory, you need to use the-R and-f option combination, or use the-RF option directly. An example of:
650) this.width=650; "Src=" https://s3.51cto.com/wyfs02/M02/8D/91/wKioL1iibtzhX-VtAAFH7Wsz75A404.jpg-wh_500x0-wm_ 3-wmp_4-s_3209562304.jpg "title=" 7.jpg "alt=" Wkiol1iibtzhx-vtaafh7wsz75a404.jpg-wh_50 "/>
This article from "Peng Brother's Blog" blog, declined reproduced!
Linux command mkdir command, rmdir command and RM command