symbolic link: find all files that link to this file

前端 未结 3 1388
挽巷
挽巷 2020-12-12 10:33

Hallo all, I need to do this in linux:

  • Given: file name \'foo.txt\'
  • Find: all files that are symbolic links to \'foo.txt\'

How to do it

3条回答
  •  鱼传尺愫
    2020-12-12 11:16

    Find the inode number of the file and then search for all files with the same inode number:

    $ 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

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

提交回复
热议问题