mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-25 23:11:02 +08:00
已翻译 by Luox
This commit is contained in:
parent
184117c11f
commit
45b3746eef
@ -1,75 +0,0 @@
|
||||
翻译 ing Luoxcat
|
||||
|
||||
Create Directory - subdirectory, other than that What mkdir command do in Linux
|
||||
================================================================================
|
||||
After knowing about ls command for listing entries inside directory, we are now moving to creating directory in Linux system. On Linux, we can use **mkdir** command. Mkdir is short for “make directory”.
|
||||
|
||||
### What is mkdir ###
|
||||
|
||||
Mkdir is a command for creating directories in Linux system. This command is a built-in command.
|
||||
|
||||
### Run mkdir command ###
|
||||
|
||||
You can type **mkdir** directly from your console to use it.
|
||||
|
||||
$ mkdir
|
||||
|
||||
By default, running mkdir without any parameter will create directory under the current directory. Here’s a sample of it :
|
||||
|
||||
![mkdir command](http://linoxide.com/wp-content/uploads/2014/01/mkdir.png)
|
||||
|
||||
From screenshot above, we created directory called **office**. When we run mkdir command, we are in **/home/pungki** directory. So then the new directory, which is office, is **created under /home/pungki** directory. **If we put an exact location** - for example : **/usr/local** - , then Linux will create a directory under **/usr/local** directory.
|
||||
|
||||
When Linux found that the directory which suppose to be created is already exist, then Linux will telling us that Linux can’t cretate it.
|
||||
|
||||
![mkdir directory exist](http://linoxide.com/wp-content/uploads/2014/01/mkdir_error.png)
|
||||
|
||||
Another pre-requisite of creating directory that **you must have access to** the location where the directory want to be created. When you don’t have it then mkdir will report an error.
|
||||
|
||||
![mkdir permission denied](http://linoxide.com/wp-content/uploads/2014/01/mkdir_permission_denied.png)
|
||||
|
||||
### Create multiple directories ###
|
||||
|
||||
We can also create multiple directories at the same time. Let say we want to create directories named **ubuntu, redhat and slackware**. Then the syntax will be like this :
|
||||
|
||||
$ mkdir ubuntu redhat slackware
|
||||
|
||||
![create multiple directories](http://linoxide.com/wp-content/uploads/2014/01/mkdir_multiple.png)
|
||||
|
||||
### Add directory include its sub-directory ###
|
||||
|
||||
When you want to created a include its sub-directory, you will need to use -p parameter. This parameter will create parent directory first, if mkdir cannot find it. Let say we want to create directory named **letter** and directory named **important** under directory letter. Then the syntax will be like this :
|
||||
|
||||
$ mkdir -p letter/important
|
||||
|
||||
![mkdir sub-directory](http://linoxide.com/wp-content/uploads/2014/01/mkdir_p.png)
|
||||
|
||||
### Set access privilege ###
|
||||
|
||||
Using **-m** parameter, we can also set the access privilege for the new directory on-the-fly. Here’s an example.
|
||||
|
||||
$ mkdir -m=r-- letter
|
||||
|
||||
The above command will create a directory named letter and give access privilege **read-only** for the **directory owner, directory group owner** and **anybody**.
|
||||
|
||||
![mkdir set privilege](http://linoxide.com/wp-content/uploads/2014/01/mkdir_m.png)
|
||||
|
||||
### Print message a message for each created directory ###
|
||||
|
||||
If we want, we can use **-v** parameter to do this. Here’s an example.
|
||||
|
||||
$ mkdir -v ubuntu redhat slackware
|
||||
|
||||
![mkdir verbose](http://linoxide.com/wp-content/uploads/2014/01/mkdir_v.png)
|
||||
|
||||
### Conclusion ###
|
||||
|
||||
Mkdir command is also one of the basic command that must known for everyone who want to learn Linux. As usual, you can always type **man mkdir** or **mkdir --help** to display mkdir manual page and explore it more detail.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/linux-mkdir-command/
|
||||
|
||||
译者:[译者ID](https://github.com/译者ID) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
@ -0,0 +1,74 @@
|
||||
在 Linux 下用 mkdir 命令来创建目录和子目录
|
||||
|
||||
==============================================================================
|
||||
了解了用 ls 命令在目录中列出条目后,现在我们要学习在 Linux 系统下创建目录。在 Linux 下,我们可以使用 **mkdir** 命令。Mkdir 是“make directory” 缩写词。
|
||||
|
||||
### mkdir 是什么呢 ###
|
||||
|
||||
Mkdir 是一个用来在 Linux 系统下创建目录的命令。此命令属于内建命令。
|
||||
|
||||
### 运行 mkdir 命令###
|
||||
|
||||
你可以在你的控制台直接键入 **mkdir** 来使用它。
|
||||
|
||||
$ mkdir
|
||||
|
||||
默认情况下,不带任何参数运行 mkdir 命令会在当前目录下创建目录。下面是参考示例:
|
||||
|
||||
![mkdir command](http://linoxide.com/wp-content/uploads/2014/01/mkdir.png)
|
||||
|
||||
从上图看出,我们创建了名为 **office** 的目录。当我们运行 mkdir 命令时,我们位于 **/home/pungki** 目录。所以这个新目录 office **创建在/home/pungki**目录下。**如果我们使用绝对路径** - 例如:**/usr/local** - , 则 Linux 会在 **/usr/local**目录下创建一个目录。
|
||||
|
||||
当 Linux 发现想要创建的目录已经存在, 那么 Linux 会提示我们 Linux 无法创建它。
|
||||
|
||||
![mkdir directory exist](http://linoxide.com/wp-content/uploads/2014/01/mkdir_error.png)
|
||||
|
||||
另外创建目录的首要条件 **你必须要有进入创建目录的目标路径的权限**。当你无法取得权限时 mkdir 会报告这个错误。
|
||||
|
||||
![mkdir permission denied](http://linoxide.com/wp-content/uploads/2014/01/mkdir_permission_denied.png)
|
||||
|
||||
### 创建多个目录 ###
|
||||
|
||||
我们也可以同时创建多个目录。比如我们要创建的目录有 **ubuntu, redhat 和 slackware**。那么语法会像这样子:
|
||||
|
||||
$ mkdir ubuntu redhat slackware
|
||||
|
||||
![create multiple directories](http://linoxide.com/wp-content/uploads/2014/01/mkdir_multiple.png)
|
||||
|
||||
### 添加包含子目录的目录 [译注:递归的创建目录] ###
|
||||
|
||||
当你要创建的目录包含有它的子目录时,你需要使用 -p 参数。如果 mkdir 找不到父目录,那么这个参数会首先帮助创建父目录。比如说我们要创建名为 **letter** 的目录,在它的目录下包含有子目录 **important**。那么语法会像这样子:
|
||||
|
||||
$ mkdir -p letter/important
|
||||
|
||||
![mkdir sub-directory](http://linoxide.com/wp-content/uploads/2014/01/mkdir_p.png)
|
||||
|
||||
### 设置权限 ###
|
||||
|
||||
使用 **-m** 参数,我们可以给即将生成的新目录设置权限。示例如下:
|
||||
|
||||
$ mkdir -m=r-- letter
|
||||
|
||||
上面的命令会创建一个名为 letter 的目录,同时给予**目录的所有者,用户组和其他用户权限**
|
||||
|
||||
![mkdir set privilege](http://linoxide.com/wp-content/uploads/2014/01/mkdir_m.png)
|
||||
|
||||
### 打印创建目录的过程信息 ###
|
||||
|
||||
如果我们要查看信息,我们可以使用 **-v** 参数来实现。示例如下:
|
||||
|
||||
$ mkdir -v ubuntu redhat slackware
|
||||
|
||||
![mkdir verbose](http://linoxide.com/wp-content/uploads/2014/01/mkdir_v.png)
|
||||
|
||||
### 总结 ###
|
||||
|
||||
Mkdir 命令也属于一个最基础的命令,对于想要学习 Linux 的朋友这个命令必须掌握。像往常一样,你可以键入**man mkdir**或**mkdir --help**来显示 mkdir 的手册页面和更加深入的探讨。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/linux-mkdir-command/
|
||||
|
||||
译者:[Luoxcat](https://github.com/Luoxcat) 校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
Loading…
Reference in New Issue
Block a user