简体   繁体   English

符号链接:查找链接到该文件的所有文件

[英]symbolic link: find all files that link to this file

Hallo all, I need to do this in linux:大家好,我需要在 linux 中执行此操作:

  • Given: file name 'foo.txt'给定:文件名'foo.txt'
  • Find: all files that are symbolic links to 'foo.txt'查找:所有符号链接到 'foo.txt' 的文件

How to do it?怎么做? Thanks!谢谢!

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 any file 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

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 eg a ->../foo.txt或者,尝试使用findlname选项,但如果您有相对a ->../foo.txt ,这将不起作用

$ find . -lname /path/to/foo.txt

I prefer to use the symlinks utility, which also is handy when searching for broken symlinks.我更喜欢使用symlinks实用程序,它在搜索损坏的符号链接时也很方便。 Install by:通过以下方式安装:

sudo apt install symlinks

Show all symlinks in current folder and subfolders:显示当前文件夹和子文件夹中的所有符号链接:

symlinks -rv .
  • -r : recursive -r :递归
  • -v : verbose (show all symlinks, not only broken ones) -v :详细(显示所有符号链接,不仅是损坏的符号链接)

To find a specific symlink, just grep :要查找特定的符号链接,只需grep

symlinks -rv . | grep foo.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM