macos 无法在 Mac 中删除目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9758704/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:59:20  来源:igfitidea点击:

Can't delete a directory in Mac

macospermissionsfilesystemsfile-permissions

提问by kambi

We have a bundle myapp.component and inside it we have a 'Contents' directory with the following permissions:

我们有一个包 myapp.component 并且在其中我们有一个具有以下权限的“Contents”目录:

drwxrwxrwx  4 root  wheel  136 Mar 18 15:05 Contents

When I try to delete this directory using

当我尝试使用删除此目录时

rm -rf Contents

It fails with the reason

它失败的原因

rm: Contents/Resources/myapp.rsrc: Permission denied
rm: Contents/Resources: Directory not empty

We do have permissions to delete the 'Contents' directory so why does it still fails?

我们确实有权删除“内容”目录,为什么它仍然失败?

Edit: If I move the bundle from /Library/Audio/Plug-Ins/Component to ~/tmp/ then It will delete the folder without any problems

编辑:如果我将包从 /Library/Audio/Plug-Ins/Component 移动到 ~/tmp/ 那么它将毫无问题地删除该文件夹

Thank you

谢谢

回答by James Aylett

You have permission to delete Contents, but not Contents/Resources/mypp.rsrc. If you do ls -lon that you'll see some more restrictive permissions.

您有权删除Contents,但没有Contents/Resources/mypp.rsrc。如果你这样做ls -l,你会看到一些更严格的权限。

In any case, from an admin account, you can do:

在任何情况下,从管理员帐户,您可以执行以下操作:

sudo rm -rf Contents

and it should work fine.

它应该可以正常工作。

回答by James

The file is probably still open.

该文件可能仍处于打开状态。

You can use the lsofcommand to list open files, and find out what's using them:

您可以使用该lsof命令列出打开的文件,并找出正在使用它们的内容:

lsof | grep "myapp\.rsrc"

lsof | grep "myapp\.rsrc"

Will probably tell you about the program with that particular file open.

可能会告诉您打开该特定文件的程序。