Linux命令中的rmdir

来源:互联网 发布:键盘美化软件下载 编辑:程序博客网 时间:2024/05/01 13:36

rmdir命令,该命令的功能是删除空目录。一个目录删除之前必须是空的。删除目录的时候也必须具有对父目录的写权限。

命令格式:rmdir [选项]   目录

命令功能:该命令从一个目录中删除一个或者多个子目录项,删除目录的时候也必须对父目录有写权限。

命令实例:

[root@centos65 local]# cd liumengyang[root@centos65 liumengyang]# [root@centos65 liumengyang]# lltotal 0drwxr-xr-x 2 root root 6 Aug 19 08:46 hellodrwxr-xr-x 2 root root 6 Aug 19 08:46 hi[root@centos65 liumengyang]# [root@centos65 liumengyang]# [root@centos65 liumengyang]# cd ..[root@centos65 local]# [root@centos65 local]# [root@centos65 local]# [root@centos65 local]# rmdir liumengyangrmdir: failed to remove `liumengyang': Directory not empty

当目录不为空的时候,不能够删除该目录


drwxr-xr-x 2 root root     6 Sep 23  2011 bindrwxr-xr-x 2 root root 65536 Aug 19 08:52 datadrwxr-xr-x 2 root root     6 Sep 23  2011 etcdrwxr-xr-x 2 root root     6 Sep 23  2011 gamesdrwxr-xr-x 5 root root  4096 Aug 18 18:07 importsourcedrwxr-xr-x 2 root root    32 Jan 14  2015 includedrwxr-xr-x 2 root root     6 Sep 23  2011 libdrwxr-xr-x 2 root root     6 Sep 23  2011 lib64drwxr-xr-x 2 root root     6 Sep 23  2011 libexecdrwxr-xr-x 2 root root     6 Aug 19 08:53 liumengyangdrwxr-xr-x 2 root root     6 Sep 23  2011 sbindrwxr-xr-x 5 root root    46 Dec  4  2013 sharedrwxr-xr-x 3 root root    22 Aug 17 12:42 sourcedatadrwxr-xr-x 2 root root     6 Sep 23  2011 src[root@centos65 local]# cd liumengyang[root@centos65 liumengyang]# [root@centos65 liumengyang]# [root@centos65 liumengyang]# lltotal 0[root@centos65 liumengyang]# [root@centos65 liumengyang]# [root@centos65 liumengyang]# mkdir hello[root@centos65 liumengyang]# [root@centos65 liumengyang]# lltotal 0drwxr-xr-x 2 root root 6 Aug 19 08:53 hello[root@centos65 liumengyang]# [root@centos65 liumengyang]# [root@centos65 liumengyang]# cd ..[root@centos65 local]# [root@centos65 local]# [root@centos65 local]# rmdir -p liumengyang/hello[root@centos65 local]# [root@centos65 local]# [root@centos65 local]# lltotal 96drwxr-xr-x 2 root root     6 Sep 23  2011 bindrwxr-xr-x 2 root root 65536 Aug 19 08:52 datadrwxr-xr-x 2 root root     6 Sep 23  2011 etcdrwxr-xr-x 2 root root     6 Sep 23  2011 gamesdrwxr-xr-x 5 root root  4096 Aug 18 18:07 importsourcedrwxr-xr-x 2 root root    32 Jan 14  2015 includedrwxr-xr-x 2 root root     6 Sep 23  2011 libdrwxr-xr-x 2 root root     6 Sep 23  2011 lib64drwxr-xr-x 2 root root     6 Sep 23  2011 libexecdrwxr-xr-x 2 root root     6 Sep 23  2011 sbindrwxr-xr-x 5 root root    46 Dec  4  2013 sharedrwxr-xr-x 3 root root    22 Aug 17 12:42 sourcedatadrwxr-xr-x 2 root root     6 Sep 23  2011 src

rmdir -p 目录路径     当子目录删除完毕的时候,父目录变为空。则父目录也一并被删除。

0 0