mkdir
![本页使用了标题或全文手工转换](https://cdn.statically.io/img/upload.wikimedia.org/wikipedia/commons/thumb/c/cd/Zh_conversion_icon_m.svg/35px-Zh_conversion_icon_m.svg.png)
此條目目前正依照其他维基百科上的内容进行翻译。 (2015年4月15日) |
Unix、DOS、OS/2和Microsoft Windows[操作系统]]以及PHP脚本语言中的mkdir(make directory,创建目录)命令用于创建一个目录。DOS、OS/2和Windows中,这条指令常被简写用作md。
用法
一般用法如下:
mkdir name_of_directory
name_of_directory是将被创建的目录名。如上所示输入后,会在当前目录下创建新目录。On Unix and Windows (with Command extensions enabled,[1] the default [2]), multiple directories can be specified, and mkdir will try to create all of them.
选项
On Unix-like operating systems, mkdir takes options. Three of the most common options are:
- -p: will also create all directories leading up to the given directory that do not exist already. If the given directory already exists, ignore the error.
- -v: display each directory that mkdir creates. Most often used with -p.
- -m: specify the octal permissions of directories created by mkdir.
-p is most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -m is commonly used to lock down temporary directories used by shell scripts.
示例
An example of -p in action is:
mkdir -p /tmp/a/b/c
If /tmp/a exists but /tmp/a/b does not, mkdir will create /tmp/a/b before creating /tmp/a/b/c.
And an even more powerful command, creating a full tree at once (this however is a Shell extension, nothing mkdir does itself):
mkdir -p tmpdir/{trunk/sources/{includes,docs},branches,tags}
If one is using variables with mkdir in a bash script, POSIX `special' built-in command 'eval' would serve its purpose.
DOMAIN_NAME=includes,docs
eval "mkdir -p tmpdir/{trunk/sources/{${DOMAIN_NAME}},branches,tags}"
This will create:
tmpdir
________|______
| | |
branches tags trunk
|
sources
____|_____
| |
includes docs
历史
In early versions of Unix (4.1BSD and early versions of System V), this command had to be setuid root as the kernel did not have an mkdir syscall. Instead, it made the directory with mknod and linked in the . and .. directory entries manually.
参见
- Filesystem Hierarchy Standard
- GNU Core Utilities
- Find – The find command coupled with mkdir can be used to only recreate a directory structure (without files).
- List of Unix programs
- List of DOS commands
参考资料
- ^ Microsoft Windows XP - Mkdir. Microsoft. [25 October 2012].
- ^ Microsoft Windows XP - Cmd. Microsoft. [25 October 2012].
外部链接
- Microsoft TechNet Mkdir article
- 单一UNIX®规范第7期,由國際開放標準組織发布 : make directories – 命令与工具(Commands & Utilities)参考,
|
|