bash Linux:命令 ls -la 显示一个文件指向另一个文件。这意味着什么?

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

Linux: The command ls -la shows a file pointing to another file. What does that mean?

bashsymlinkls

提问by Dao Lam

When I type ls -lato list all the files, I see this:

当我键入ls -la以列出所有文件时,我看到:

11 Jul  9 12:04 libcrypto.so -> libcrypto.so.0

I tried to change the name of libcrypto:

我试图更改 libcrypto 的名称:

mv libcryto.so libpmcrypto.so

And now it shows:

现在它显示:

11 Jul  9 12:04 libpmcrypto.so -> libcrypto.so.0

Does that affect anything? And what does the arrow mean?

这有什么影响吗?箭头是什么意思?

回答by Ian McLaird

The file in question is a symbolic link. This is conceptually similar to the idea of a shortcut, but it appears to be the real file if you use it (Open it, copy it, etc.). The symbolic link is another name that "points to" the real file. When you do ls -lit also shows you which file is pointed to by the link. Renaming the link has no effect on the original file, but may break things that rely on the link name, just as with any other file name. Deleting the link just removes the pointer, and has no effect on the original file. Deleting the original file will leave the link in a "broken state" where the link points to nothing.

有问题的文件是一个符号链接。这在概念上类似于快捷方式的想法,但如果您使用它(打开它、复制它等),它似乎是真正的文件。符号链接是“指向”真实文件的另一个名称。执行ls -l此操作时,它还会显示链接指向的文件。重命名链接对原始文件没有影响,但可能会破坏依赖链接名称的内容,就像使用任何其他文件名一样。删除链接只会删除指针,对原始文件没有影响。删除原始文件将使链接处于“损坏状态”,其中链接指向任何内容。

EditYou can't really edit what symbolic links point to. You can delete them with rmand then recreate them with the ln -scommand. Take a look at the man pages for more information.

编辑您无法真正编辑符号链接指向的内容。您可以删除它们,rm然后使用ln -s命令重新创建它们。查看手册页以获取更多信息。

回答by Amit Verma

->means libpmcrypto.so is a Symbolic link and the information stored in libcrypto.so.0 is accessible through the libpmcrypto.so file.

->意味着 libpmcrypto.so 是一个符号链接,存储在 libcrypto.so.0 中的信息可以通过 libpmcrypto.so 文件访问。

How to create a symbolic link:

如何创建符号链接:

ln -s [TARGET DIRECTORY OR FILE] ./[SHORTCUT]

for example:

例如:

ln -s /usr/local/apache/logs /home/el/logs

If you delete the soft link itself (/home/el/logs), the file (/usr/local/apache/logs) would still be there.

如果您删除软链接本身 (/home/el/logs),文件 (/usr/local/apache/logs) 仍然存在。

How to find symbolic links:

如何查找符号链接:

find ./ -type l

read man lnfor more information on links.

阅读man ln有关链接的更多信息。

回答by meda

ls -lawill display files pointing to module using symbolic links

ls -la将使用符号链接显示指向模块的文件

For example in your library directory you have file pointing to the .so files (shared object).

例如,在您的库目录中,您有指向 .so 文件(共享对象)的文件。

This means it does not need to be recompiled. You have no easy way of telling how files are linked.

这意味着它不需要重新编译。您没有简单的方法来说明文件是如何链接的。

回答by Jose Munoz

Yes that does changes something, in fact you shouldn't change a shared library because when a 3rd-party program tries to call libcryto.soits not going to be there any more.

是的,这确实改变了一些东西,事实上你不应该改变共享库,因为当第 3 方程序尝试调用libcryto.so 时,它不会再存在了。

But if you're sure you want to change the name, I would recommend you to call nautilus in superuser mode:

但是,如果您确定要更改名称,我建议您在超级用户模式下调用 nautilus:

sudo nautilus /THE/FOLDER/WHERE/YOUR/FILE/IS

And edit it manually, by adding .0to the end of the symlink name. You're changing part of its name so whenever a program tries to call it, its not going to be able to locate it.

并通过在符号链接名称的末尾添加.0来手动编辑它。您正在更改其名称的一部分,因此每当程序尝试调用它时,它都无法找到它。