bash 我无法使用 rmdir 删除目录,因为目录中似乎有一个无法删除的同名文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36361387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
I cannot use rmdir to remove a directory as there seems to be a file in the directory with the same name that cannot be deleted
提问by JandD
Hi guys I am a complete beginner to programming and have tried to google this answer but with no joy.
大家好,我是一个完整的编程初学者,并试图用谷歌搜索这个答案,但没有任何乐趣。
I am following Zed Shaw's "Command Line Crash Course " and have hit a wall with rmdir.
我正在关注 Zed Shaw 的“命令行速成课程”并且用 rmdir 碰壁了。
I use a mac and know to delete hidden files like .DS_Store
and have done so for my directory. However, it still says the directory is not empty and ls -la
seems to show a file that shares the directory name:
我使用 mac 并且知道删除隐藏文件,例如.DS_Store
并且已经为我的目录这样做了。但是,它仍然说目录不为空,并且ls -la
似乎显示了一个共享目录名称的文件:
See below for directory joe
目录见下方 joe
drwxr-xr-x 3 MyLaptop staff 102 1 Apr 16:52 .
drwxr-xr-x 4 MyLaptop staff 136 31 Mar 22:32 ..
drwxr-xr-x 3 MyLaptop staff 102 1 Apr 16:51 joe
I have tried to remove this file but it will not allow me to and I cannot remove the directory, can anyone's suggest a solution?
我曾尝试删除此文件,但它不允许我删除并且我无法删除该目录,任何人都可以提出解决方案吗?
回答by Bakuriu
That is nota file. The d
at the beginning of a line tells you that it is a directory. In fact it is the exact directory you are trying to delete.
那不是文件。将d
在一行的开头告诉你,它是一个目录。事实上,它正是您要删除的目录。
The rmdir
command requires that the joe
directory be empty. To check if joe
is empty use:
该rmdir
命令要求joe
目录为空。要检查是否joe
为空,请使用:
$ ls -la joe
Or move into that directory first:
或者先进入该目录:
$ cd joe
$ ls -la
You are instead using ls -la
in the parent directory of joe
, and hence joe
itself is showing up in the contents.
您改为ls -la
在 的父目录中使用joe
,因此joe
它本身显示在内容中。
So check which files are inside joe
and delete them using rm
.
The .
and ..
entries don't really count as these are references to the current and parent directory.
所以检查里面有哪些文件joe
并使用rm
. 在.
和..
条目真的不指望,因为这些是当前和父目录的引用。
Note that rm
can also delete directories, so you could simply do rm -r joe
to delete all the files inside joe
andthe joe
directory itself.
请注意,rm
也可以删除目录,所以你可以简单地做rm -r joe
删除里面的所有文件joe
和该joe
目录本身。
回答by user6124839
You can also use
你也可以使用
$ rm -r joe
$ rm -r 乔
The -r option to the rm command will recursively delete the contents of the directory, and the directory itself.
rm 命令的 -r 选项将递归删除目录的内容和目录本身。
From the rm man page:
从 rm 手册页:
-r, -R, --recursive remove directories and their contents recursively
-r, -R, --recursive remove directories and their contents recursively