Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

symbolic link: find all files that link to this file

Tags:

linux

symlink

People also ask

Which of the following commands is used to find all the files symbolic link files in the current working directory which have the file permission as 666?

ls command to find a symbolic link in UNIX systems when you run the ls -lrt command in any directory it prints permission details of each file and directories, if you look carefully for links that String starts with a small L ( l for the link).

How do I get a list of symbolic links?

Use the ls -l command to check whether a given file is a symbolic link, and to find the file or directory that symbolic link point to. The first character “l”, indicates that the file is a symlink. The “->” symbol shows the file the symlink points to.

How do I list all symbolic links in Windows?

In Command Prompt, run this command: dir /AL /S c:\ A list of all of the symbolic links in the c:\ directory will be returned.

Does find follow symbolic links?

By default, find examines symbolic links themselves when it finds them (and, if it later comes across the linked-to file, it will examine that, too). If you would prefer find to dereference the links and examine the file that each link points to, specify the ' -L ' option to find .


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:

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

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:

$ 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

I prefer to use the symlinks utility, which also is handy when searching for broken symlinks. Install by:

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)

To find a specific symlink, just grep:

symlinks -rv . | grep foo.txt