Linux删除目录


如果这个目录不需要了,我们可以使用“rmdir”命令来删除一个目录,用法如下:

[root@Linux ~]# ll
总计 60
-rw------- 1 root root 865 03-15 04:12 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 03-14 20:34 Desktop
-rw-r--r-- 1 root root 27964 03-15 04:12 install.log
-rw-r--r-- 1 root root 5069 03-15 04:11 install.log.syslog
drwxr-xr-x 2 root root 4096 03-19 12:36 myfile
[root@Linux ~]# rmdir myfile
[root@Linux ~]# ll
总计 56
-rw------- 1 root root 865 03-15 04:12 anaconda-ks.cfg
drwxr-xr-x 2 root root 4096 03-14 20:34 Desktop
-rw-r--r-- 1 root root 27964 03-15 04:12 install.log
-rw-r--r-- 1 root root 5069 03-15 04:11 install.log.syslog

我们先看看当前目录下有一个myfile的目录,我们不需要这个目录了,我们可以使用“rmdir myfile”命令来删除这个目录,然后使用ll命令验证一下。

注意的是,使用这个命令来删除一个目录的时候,那么这个目录下必须是没有任何文件和文件夹的,我们看看如下的操作:

[root@Linux ~]# mkdir myfile
[root@Linux ~]# cd myfile cd命令是切换目录,这里就是进入myfile
[root@Linux myfile]# mkdir one
[root@Linux myfile]# cd .. ..表示当前目录的上一层目录
[root@Linux ~]# rmdir myfile
rmdir: myfile: 目录非空

我们在myfile目录下建立了一个one的目录,当我们删除myfile目录时,提示目录为空,所以必须将这个目录下的所有文件和目录全部删除之后,才能删除这个目录。

声明:初心|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - Linux删除目录


愿你勿忘初心,并从一而终