zoukankan      html  css  js  c++  java
  • linux一步一脚印---mkdir命令

    1 命令功能(简要说明):

        用来创建目录,要求需要创建目录的用户在当前目录中具有写权限,并且新建的目录不能是当前目录已存在的目录。

    2 命令语法:

        mkdir 【选项】 【目录名】     #注:【】中的内容为非必选项

    3 命令选项(只做常用命令参数讲述):

     使用帮助命令:man mkdir 或 mkdir --help

      -m,--mode==MODE  设置权限,这里使用帮助命令得出(set file mode (as in chmod), not a=rwx - umask)不是很懂这串英文说的什么意思???

      -p,--parents 递归创建目录,即使父目录存在也不报错

      -v,--verboe 详细的打印出所有创建的目录详细信息

      -z,--context=CTX (set the SELinux security context of each created directory to CTX)这一串描述又是个什么意思不是很懂???

     

    4 使用范例:

      (1)mkdir 目录名 【,目录名】

    #可一次性创建多个目录
    [root@localhost command_test]# mkdir dir1 dir2 dir3
    [root@localhost command_test]# ll
    总用量 12
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir1
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir2
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir3
    
    #创建带有空格的目录名,但不建议这样做
    [root@localhost command_test]# mkdir "dir4 xx"    
    [root@localhost command_test]# ll
    总用量 16
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir1
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir2
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir3
    drwxr-xr-x. 2 root root 4096 7月  25 04:22 dir4 xx

      (2)mkdir -m 目录名 创建目录并设置权限

    #批量设置权限
    [root@localhost command_test]# mkdir -m 777 dir5 dir6 dir7
    [root@localhost command_test]# ll
    总用量 12
    drwxrwxrwx. 2 root root 4096 7月  25 04:25 dir5
    drwxrwxrwx. 2 root root 4096 7月  25 04:25 dir6
    drwxrwxrwx. 2 root root 4096 7月  25 04:25 dir7
    #注意普通创建目录与使用-m参数设置权限创建目录区别
    
    [root@localhost command_test]# mkdir dir1
    [root@localhost command_test]# ll
    总用量 4
    drwxr-xr-x. 2 root root 4096 7月 25 03:53 dir1
    [root@localhost command_test]# mkdir -m 777 dir2
    [root@localhost command_test]# ll
    总用量 8
    drwxr-xr-x. 2 root root 4096 7月 25 03:53 dir1
    drwxrwxrwx. 2 root root 4096 7月 25 03:53 dir2
    [root@localhost command_test]# mkdir --mode a=rwx-w dir1
    [root@localhost command_test]# ll
    总用量 4
    dr-xr-xr-x. 2 root root 4096 7月  25 03:59 dir1
    #注意下面使用 u=所有者,g=所属组,o=其他用户
    [root@localhost command_test]# mkdir -m u=rw-,g=rw-,o=--- dir2 
    [root@localhost command_test]# ll
    总用量 4
    drw-rw----. 2 root root 4096 7月  25 04:03 dir2

      (3)mkdir -pv 目录名 递归创建目录,并输出目录详细信息

    #下列为递归创建目录示例
    [root@localhost command_test]# mkdir -pv  dir1/dir2/dir3   
    mkdir: 已创建目录 "dir1"
    mkdir: 已创建目录 "dir1/dir2"
    mkdir: 已创建目录 "dir1/dir2/dir3"
    [root@localhost command_test]# cd dir1
    [root@localhost dir1]# cd dir2
    [root@localhost dir2]# cd dir3
    #刚接触下面这两个命令感觉特别有意思
    [root@localhost command_test]# mkdir -pv  test1/{test2,test3/{test4,test5}}
    mkdir: 已创建目录 "test1"
    mkdir: 已创建目录 "test1/test2"
    mkdir: 已创建目录 "test1/test3"
    mkdir: 已创建目录 "test1/test3/test4"
    mkdir: 已创建目录 "test1/test3/test5"
    [root@localhost command_test]# mkdir -pv  dir1/{dir2,dir3}/{dir4,dir5}     
    mkdir: 已创建目录 "dir1"
    mkdir: 已创建目录 "dir1/dir2"
    mkdir: 已创建目录 "dir1/dir2/dir4"
    mkdir: 已创建目录 "dir1/dir2/dir5"
    mkdir: 已创建目录 "dir1/dir3"
    mkdir: 已创建目录 "dir1/dir3/dir4"
    mkdir: 已创建目录 "dir1/dir3/dir5"
  • 相关阅读:
    如何组建开发团队-建立畅通的沟通渠道
    如何组建开发团队-激励团队气势
    文件夹名与类名一致造成的命名空间无法识别的问题
    SQL Server 还原错误“restore database正在异常终止 错误 3154”
    S​Q​L​ ​S​e​r​v​e​r​ ​服务无法启动,错误1069解决办法
    无法升级数据库....因为此版本的 SQL Server 不支持该数据库的非发布版本(539) 解决方案
    图解Microsoft SQL Server——“远程过程调用失败 [0x800706be] 错误“。
    Eclipse: Android Device Chooser
    部署网站时的错误“one of its dependencies.试图加载格式不正确的程序。”解决方案。
    把char赋值到string里面
  • 原文地址:https://www.cnblogs.com/king-of-purple/p/9363393.html
Copyright © 2011-2022 走看看