我无法使用 rmdir 删除目录,因为目录中似乎有一个无法删除的同名文件

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

大家好,我是编程的新手,已经尝试 google 这个答案,但并不开心。

我正在关注 Zed Shaw 的 "Command Line Crash Course ",但在使用 rmdir 时遇到了困难。

我使用 mac 并且知道删除像 .DS_Store 这样的隐藏文件并且已经为我的目录这样做了。但是,它仍然说目录不为空并且 ls -la 似乎显示共享目录名称的文件:

参见下面的目录 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

我已尝试删除此文件,但它不允许我删除目录,任何人都可以提出解决方案吗?

那是不是一个文件。行首的 d 告诉您这是一个目录。事实上,它正是您要删除的目录。

rmdir 命令要求 joe 目录为空。要检查 joe 是否为空,请使用:

$ ls -la joe

或者先进入那个目录:

$ cd joe
$ ls -la

您在 joe 的父目录中使用 ls -la,因此 joe 本身出现在内容中。

因此检查 joe 中有哪些文件并使用 rm 删除它们。 ... 条目并不算数,因为它们是对当前目录和父目录的引用。


注意 rm 也可以删除目录,所以你可以简单地执行 rm -r joe 来删除 joe 中的所有文件joe 目录本身。

您也可以使用

$ rm -r 乔

rm 命令的 -r 选项将递归删除目录的内容和目录本身。

来自 rm 手册页:

     -r, -R, --recursive
     remove directories and their contents recursively