您的位置:首页 > 其它

目录创建与删除命令:mkdir和rmdir

2016-10-16 20:27 253 查看
mkdir:make directory目录创建

命令作用:

用来创建指定名称的目录,要求创建目录的用户在当前目录中有r权限,并且指定目录名不能是当前目录中已有的目录;

2:命令格式:
mkdir [options] directory

3.参数说明:
-p:parents(父母复数形式的意思) 如果是一个路径名称,若此路径中的某些目录不存在,加上-p选项系统会自动创建路径中不存在的目录;

-v:verbose(详细)每次创建目录都显示创建信息;

-m:mode(模式)创建目录的时候设定权限模式;

4.范例:

[root@localhost ~]# mkdir test
[root@localhost ~]# ll
total 108
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
drwxr-xr-x. 2 root root 4096 Oct 15 21:53 test

[root@localhost ~]# mkdir -v test1
mkdir: created directory `test1'
[root@localhost ~]# ll
total 112
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
drwxr-xr-x. 2 root root 4096 Oct 15 21:53 test

[root@localhost ~]# mkdir ./a/b/c
mkdir: cannot create directory `./a/b/c': No such file or directory
[root@localhost ~]# mkdir -p ./a/b/c
[root@localhost ~]# ll
total 116
drwxr-xr-x. 3 root root 4096 Oct 15 21:55 a
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
drwxr-xr-x. 2 root root 4096 Oct 15 21:53 test
drwxr-xr-x. 2 root root 4096 Oct 15 21:54 test1

[root@localhost ~]# mkdir -m 777 ./b
[root@localhost ~]# ll -d b
drwxrwxrwx. 2 root root 4096 Oct 15 22:03 b

rmdir:remove directory目录删除

命令作用:

删除空目录;

2.命令格式:
rmdir [options] directory

3.参数说明:
-p:(parents父母复数形式的意思)当子目录被删除,父目录也为空时,父目录也一并被删除;

-v:(verbose详细)显示命令执行过程信息;

4.范例:

[root@localhost ~]# rmdir test
[root@localhost ~]# ll
total 116
drwxr-xr-x. 3 root root 4096 Oct 15 21:55 a
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
drwxrwxrwx. 2 root root 4096 Oct 15 22:03 b
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
drwxr-xr-x. 2 root root 4096 Oct 15 21:54 test1

[root@localhost ~]# rmdir a
rmdir: failed to remove `a': Directory not empty
[root@localhost ~]# rmdir -p a/b/c
[root@localhost ~]# ll
total 112
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
drwxrwxrwx. 2 root root 4096 Oct 15 22:03 b
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
drwxr-xr-x. 2 root root 4096 Oct 15 21:54 test1

[root@localhost ~]# rmdir -v b
rmdir: removing directory, `b'
[root@localhost ~]# ll
total 108
-rw-------. 1 root root 1645 Mar 16 2016 anaconda-ks.cfg
-rw-r--r--. 1 root root 50101 Mar 16 2016 install.log
-rw-r--r--. 1 root root 10608 Mar 16 2016 install.log.syslog
drwxr-xr-x. 2 root root 4096 Oct 15 21:54 test1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  用户
相关文章推荐