mkdir命令

【mkdir】   创建目录     mkdir ===make directory

命令格式:

mkdir [OPTION]... DIRECTORY

命令功能:

通过 mkdir 命令可以实现在指定位置创建以 DirName(指定的文件名)命名的文件夹或目录。要创建文件夹或目录的用户必须对所创建的文件夹的父文件夹具有写权限。并且,所创建的文件夹(目录)不能与其父目录(即父文件夹)中的

文件名重名,即同一个目录下不能有同名的(区分大小写)。

命令参数:

-m, --mode=MODE        设置文件权限(像chmod),而不是rwx-umask

-p, --parents                     一次建立多个目录

-v, --verbose  echo         打印出每次创建目录的新信息

                  --version

                  --help

命令实例:

实例1:创建一个空目录

命令:

mkdir nihao

输出:

[root@localhost /]# ls

bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt

[root@localhost /]# mkdir nihao

[root@localhost /]# ll

drwxr-xr-x.  2 root root  4096 Jul  6 00:03 nihao

实例2:递归创建多个目录

命令:

mkdir -p a1/a2 a3/a4

输出:

root@localhost nihao]# ls

[root@localhost nihao]# mkdir a1/a2

mkdir: cannot create directory `a1/a2': No such file or directory

[root@localhost nihao]# mkdir -p a1/a2

[root@localhost nihao]# cd a1

[root@localhost a1]# ll

drwxr-xr-x. 2 root root 4096 Jul  6 00:01 a2

实例3:设置文件权限

命令:

mkdir -m 755 nihao

输出:

[root@localhost /]# mkdir -m 777 niaho

[root@localhost /]# ll |grep niaho

drwxrwxrwx.  2 root root  4096 Jul  6 00:05 niaho

[root@localhost /]# mkdir -m 777 nihao

mkdir: cannot create directory `nihao': File exists

[root@localhost /]# chmod 755 hello

chmod: cannot access `hello': No such file or directory

说明:

帮助里说类似chmod,试了下发现不一样chmod是给已存在的目录文件改权限,如果文件目录不存在用chmod会报错,mkdir只给还没创建的目录添加文件,如果文件已存在会报错

实例4:创建新目录时显示信息

命令:

mkdir -v hey

输出:

[root@localhost hi]# mkdir -v hey

mkdir: created directory `hey'

实例5:递归创建目录并显示信息

命令

mkdir -vp /hello{/a,/b,/c{/c1/c2},/d}

输出:

[root@localhost hi]# mkdir -vp /hello{/a,/b,/c{/c1/c2},/d}

mkdir: created directory `/hello'

mkdir: created directory `/hello/a'

mkdir: created directory `/hello/b'

mkdir: created directory `/hello/c{'

mkdir: created directory `/hello/c{/c1'

mkdir: created directory `/hello/c{/c1/c2}'

mkdir: created directory `/hello/d'

[root@localhost hi]# mkdir -vp /hello/{a/,b/,c/{c1/,c2/},d/}

mkdir: created directory `/hello'

mkdir: created directory `/hello/a/'

mkdir: created directory `/hello/b/'

mkdir: created directory `/hello/c'

mkdir: created directory `/hello/c/c1/'

mkdir: created directory `/hello/c/c2/'

mkdir: created directory `/hello/d/'

[root@localhost /]# mkdir -vp /hello{/a,/b,/c{/c1,/c2},/d}

mkdir: created directory `/hello'

mkdir: created directory `/hello/a'

mkdir: created directory `/hello/b'

mkdir: created directory `/hello/c'

mkdir: created directory `/hello/c/c1'

mkdir: created directory `/hello/c/c2'

mkdir: created directory `/hello/d'

说明:第一次出错,和网站上的对比以为是斜杠位置不对,后检查是少个逗号,加上就好了

转载于:https://www.cnblogs.com/topaz1618/p/4631209.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值