Linux 符号链接:查找链接到该文件的所有文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6184849/
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
symbolic link: find all files that link to this file
提问by lukmac
Hallo all, I need to do this in linux:
大家好,我需要在 linux 中执行此操作:
- Given: file name 'foo.txt'
- Find: all files that are symbolic links to 'foo.txt'
- 给定:文件名'foo.txt'
- 查找:所有作为“foo.txt”符号链接的文件
How to do it? Thanks!
怎么做?谢谢!
采纳答案by DigitalRoss
It depends, if you are trying to find links to a specific file that is called foo.txt,
then this is the only good way:
这取决于,如果您试图找到指向特定文件的链接,foo.txt,
那么这是唯一的好方法:
find -L / -samefile path/to/foo.txt
On the other hand, if you are just trying to find links to anyfile that happens to be named foo.txt
, then something like
另一方面,如果您只是想查找指向任何碰巧命名的文件的链接foo.txt
,则类似于
find / -lname foo.txt
or
或者
find . -lname \*foo.txt # ignore leading pathname components
回答by dogbane
Find the inode number of the file and then search for all files with the same inode number:
查找文件的 inode 编号,然后搜索所有具有相同 inode 编号的文件:
$ ls -i foo.txt
41525360 foo.txt
$ find . -follow -inum 41525360
Alternatively, try the lname
option of find
, but this won't work if you have relative symlinks e.g. a -> ../foo.txt
或者,尝试 的lname
选项find
,但如果您有相对符号链接,这将不起作用,例如a -> ../foo.txt
$ find . -lname /path/to/foo.txt
回答by Nik
I prefer to use the symlinks
utility, which also is handy when searching for broken symlinks. Install by:
我更喜欢使用该symlinks
实用程序,它在搜索损坏的符号链接时也很方便。安装方式:
sudo apt install symlinks
Show all symlinks in current folder and subfolders:
显示当前文件夹和子文件夹中的所有符号链接:
symlinks -rv .
-r
: recursive-v
: verbose (show all symlinks, not only broken ones)
-r
: 递归-v
: 详细(显示所有符号链接,不仅是损坏的符号链接)
To find a specific symlink, just grep
:
要查找特定的符号链接,只需grep
:
symlinks -rv . | grep foo.txt