The mkdir command is is used to create new directories.

A directory, referred to as a folder in some operating systems, appears to the user as a container for other directories and files. However, Unix-like operating systems treat directories as merely a special type of file that contains a list of file names and their corresponding inode numbers. Each inode number refers to an inode, which is located in inode tables (which are kept at strategic locations around the filesystem) and which contains all information about a file (e.g., size, permissions and date of creation) except its name and the actual data that the file contains.

mkdir has the following syntax:

mkdir [option] directory_name(s)

directory_name is the name of any directory that the user is asking mkdir to create. Any number of directories can be created simultaneously.

Thus, for example, the following command would create three directories within the current directory (i.e., the directory in which the user is currently working) with the names dir_1dir_2 and dir_3:

mkdir dir_1 dir_2 dir_3

If a directory name provided as an argument (i.e., input) to mkdir is the same as that of an existing directory or file in the same directory in which the user is asking mkdir to create the new directory, mkdir will return a warning message such as mkdir: cannot create directory `dir_1': File exists and will not create a file with that name. However, it will then continue to create directories for any other names provided as arguments.

It is necessary for a user to have write permission (i.e., permission from the system to create or change a file or directory) in the parent directory (i.e., the directory in which the new directory is to be created) in order to be able to create a new directory.

Directories created by mkdir automatically include two hidden directories, one representing the directory just created (and represented by a single dot) and the other representing its parent directory (and represented by two consecutive dots). This can be seen by using the ls (i.e., list) command with its -a option, which tells ls to show all directories and files, (including hidden ones) in any directory provided to it as an argument, or in the current directory if there are no arguments, i.e.,

ls -a

mkdir's -m option is used to control the permissions of new directories. New directories are by default created with the read, write and execute (i.e., run as a program if a program) permissions enabled for the owner (i.e., the creator of the directory by default) and group and the read and execute permissions enabled for other users. Thus, for example, to create a directory named dir_4 for which all three types of permissions were enabled for all users, the sequence 777 would be employed after -m, for example:

mkdir -m 777 dir_4

The first digit represents the owner, the second represents the group and the third represents other users. The number 7 represents all three types of permission (i.e., read, write and execute), 6 stands for read and write only, 5 stands for read and execute, 4 is read only, 3 is write and execute, 2 is write only, 1 is execute only and 0 is no permissions.

Thus, for example, to create a new directory named dir_5 for which the owner has read and write permissions, the group has read permission and other users have no permissions, the following would be used:

mkdir -m 640 dir_5

The -p (i.e., parents) option creates the specified intermediate directories for a new directory if they do not already exist. For example, it can be used to create the following directory structure:

mkdir -p food/fruit/citrus/oranges

It is very easy to confirm that this series of directories has been created by using the du (i.e., disk usage) command with the name of the first directory as an argument. In the case of the above example this would be

du food

Other options include -v (i.e., verbose), which returns a message for each created directory, --help, which returns brief information about mkdir, and --version, which returns the version number of the currently installed mkdir program.

Additional information about mkdir can be obtained from the mkdir man page.

Directories can be removed with the rmdir and rm commands.

The mkdir Command的更多相关文章

  1. ./vi: line 2: mkdir: command not found

    当前两天博主在写脚本的时候,运行脚本时候总是出现此消息,很郁闷, 开始我以为可能是我mkdir的函数库依赖的问题,但是当我用其他的脚本创建 目录的时候,命令又可以用了,找了半天,终于找到了答案 --- ...

  2. 在 Linux 下用 mkdir 命令来创建目录和子目录

    mkdir 是什么呢 Mkdir 是一个用来在 Linux 系统下创建目录的命令.此命令属于内建命令. 运行 mkdir 命令 你可以在你的控制台直接键入 mkdir 来使用它. $ mkdir 默认 ...

  3. Linux学习之文件操作

    Linux,一起学习进步-    mkdir The mkdir command is used to create directories.It works like this: mkdir命令是用 ...

  4. DAY1 linux 50条命令

    1. tar压缩,解压缩 tar -cvf *** (压缩) tar -xvf ***  (解压缩) [root@bogon ~]# tar cvf test.tar test/ test/ test ...

  5. codecademy-command line_filesystem

    $:shell prompt (命令提示符) In the terminal, first you see $. This is called a shell prompt. It appears w ...

  6. 【转载】linux内核启动android文件系统过程分析

    主要介绍linux 内核启动过程以及挂载android 根文件系统的过程,以及介绍android 源代码中文件系统部分的浅析. 主要源代码目录介绍Makefile (全局的Makefile)bioni ...

  7. Google Code Jam 2010 Round 1B Problem A. File Fix-it

    https://code.google.com/codejam/contest/635101/dashboard#s=p0   Problem On Unix computers, data is s ...

  8. Automake

    Automake是用来根据Makefile.am生成Makefile.in的工具 标准Makefile目标 'make all' Build programs, libraries, document ...

  9. LVM学习

    LVM Logical Volume Manager Volume management creates a layer of abstraction over physical storage, a ...

随机推荐

  1. for循环相关的一个问题

    首先,我在for循环外定义了两个变量. //在4条直线方向,获取预置点两端的8个点的棋盘信息 ,r=,c=;//step代表直线,r,c分别代表加上偏移量之后的坐标 ,myCount=,hisCoun ...

  2. linux下,文件的权限和数字对应关系详解

    命令 chmod ABC file 其中A.B.C各为一个数字,分别表示User.Group.及Other的权限. A.B.C这三个数字如果各自转换成由"0"."1&qu ...

  3. BZOJ2338: [HNOI2011]数矩形

    题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2338 中学数学老师告诉我们,一个矩形的两条对角线相等,所以只要把所有的边拿出来,记录下中点坐标 ...

  4. Frame Stacking(拓扑排序)

    题目链接:http://acm.tju.edu.cn/toj/showp1076.html1076.   Frame Stacking Time Limit: 1.0 Seconds   Memory ...

  5. c语言基础学习08_关于内存管理的复习

    =============================================================================对于c语言来讲,内存管理是一个很重要的内容,它 ...

  6. python数据类型(一)

    1.数据类型 python中数有四种类型:整数.长整数.浮点数和复数. 整数, 如 1 长整数 是比较大的整数 浮点数 如 1.23.3E-2 复数 如 1 + 2j. 1.1 + 2.2j 2. 自 ...

  7. JavaScript实现职责链模式

    什么是职责链模式 职责链模式的定义是:使多个对象都有机会处理请求,从而避免请求的发送者和接收者之间的耦合关系,将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止.举个例子:当你从公 ...

  8. C# 小笔记

    1,Using using (var ws = new WebSocket ("ws://dragonsnest.far/Laputa")) { ws.OnMessage += ( ...

  9. 【开发技术】web.xml vs struts.xml

    web.xml用来配置servlet,监听器(Listener),过滤器(filter),还有404错误跳转页面,500,等还配置欢迎页面等,总之一句话,就是系统总配置方案写在web.xml中 str ...

  10. Oracle问题之ORA-01609、ORA-00362

    Oracle问题之ORA-01609: 日志 4 是线程 1 的当前日志 - 无法删除成员 Oracle问题之ORA-00362: 要求输入成员以组成组 4 中的有效日志文件