跳转到内容

mkdir

本页使用了标题或全文手工转换
维基百科,自由的百科全书

这是本页的一个历史版本,由Qiyue2001留言 | 贡献2015年4月15日 (三) 10:19 建立内容为“{{noteTA|G1=IT}} {{subst:Translating/auto|tpercent=10}} {{lowercase|title=mkdir}} UnixDOSOS/2Microsoft Windows[操作系统...”的新页面)编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

UnixDOSOS/2Microsoft Windows[操作系统]]以及PHP脚本语言中的mkdirmake 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.

参见

参考资料

  1. ^ Microsoft Windows XP - Mkdir. Microsoft. [25 October 2012]. 
  2. ^ Microsoft Windows XP - Cmd. Microsoft. [25 October 2012]. 

外部链接