删除指向目录的符号链接 [英] Remove a symlink to a directory

查看:78
本文介绍了删除指向目录的符号链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个指向重要目录的符号链接.我想摆脱该符号链接,同时保留目录.

I have a symlink to an important directory. I want to get rid of that symlink, while keeping the directory behind it.

我尝试了rm并返回了rm: cannot remove 'foo'.
我尝试了rmdir并返回了rmdir: failed to remove 'foo': Directory not empty
然后,我通过rm -frm -rfsudo rm -rf

I tried rm and get back rm: cannot remove 'foo'.
I tried rmdir and got back rmdir: failed to remove 'foo': Directory not empty
I then progressed through rm -f, rm -rf and sudo rm -rf

然后我去找我的后援.

有没有一种方法可以消除符号链接,而不会把婴儿的洗澡水扔掉?

Is there a way to get rid of the symlink with out throwing away the baby with the bathwater?

推荐答案

# this works:
rm foo
# versus this, which doesn't:
rm foo/

基本上,您需要告诉它删除文件,而不是删除目录.我相信rmrmdir之所以存在差异,是因为C库对待它们的方式不同.

Basically, you need to tell it to delete a file, not delete a directory. I believe the difference between rm and rmdir exists because of differences in the way the C library treats each.

无论如何,第一个应该起作用,而第二个应该抱怨foo是目录.

At any rate, the first should work, while the second should complain about foo being a directory.

如果上述操作无效,请检查您的权限.您需要对包含目录的写入权限才能删除文件.

If it doesn't work as above, then check your permissions. You need write permission to the containing directory to remove files.

这篇关于删除指向目录的符号链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆