bash 删除指向不存在目录的符号链接的安全方法(对于 python 二进制文件)

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

Safe way to remove a symbolic link to an non-existing directory (for the python binary)

bashdirectorysymlink

提问by uploada

I accidentally typed:

我不小心输入了:

sudo ln -sf /usr/local/bin/python2.5/ /usr/bin/python 

instead of:

代替:

sudo ln -sf /usr/local/bin/python2.5 /usr/bin/python

Now bash tells me that /usr/bin/python is not a directory whenever I run python.

现在 bash 告诉我,每当我运行 python 时,/usr/bin/python 都不是目录。

ls -l /usr/bin/python gives me expectedly /usr/bin/python --> /usr/local/bin/python2.5/

Is there any safe way to remove that symbolic link to a directory (that does not exist) and replace it with a link to the intended file?

是否有任何安全的方法可以删除指向目录(不存在)的符号链接并将其替换为指向预期文件的链接?

Arigato in advance if you have any ideas.

如果您有任何想法,请提前 Arigato。

I am stuck....

我卡住了....

回答by krtek

you can simply remove the link with rm :

您可以简单地使用 rm 删除链接:

rm /usr/bin/python

回答by Marcelo Cantos

You remove a symlink the same way you remove a regular file, even if it's a symlink to a directory. (If the target doesn't exist, it's a moot point whether it was intended to be a directory or a file.)

您可以像删除常规文件一样删除符号链接,即使它是指向目录的符号链接。(如果目标不存在,那么它是打算作为目录还是文件是一个有争议的问题。)

回答by kesten

this worked for me. Although I originally created the symlink following a blender tutorial http://wiki.blender.org/index.php/Dev:2.5/Doc/Building_Blender/Linux/Troubleshooting#Setting_Python_Path_in_SCons

这对我有用。虽然我最初是按照搅拌机教程创建的符号链接 http://wiki.blender.org/index.php/Dev:2.5/Doc/Building_Blender/Linux/Troubleshooting#Setting_Python_Path_in_SCons

using this command:

使用这个命令:

sudo update-alternatives --install /usr/bin/python python /your/path/to/python3.2 1

(see man page for update-alternatives for info. Terminal>man update-alternatives)

(有关信息,请参阅更新替代品的手册页。终端>人更新替代品)

I'm curious to know how badly I've messed things up for the update-alternatives system of managing different versions of same-named software. For instance, i think scons runs on python2.7 while blender builds internally with python3.2. Will things resolve correctly still? We shall see...

我很想知道我把管理同名软件的不同版本的更新替代系统搞得一团糟。例如,我认为 scons 在 python2.7 上运行,而 Blender 在内部使用 python3.2 构建。事情还会正确解决吗?我们会看到...