I had created many symbolic links on various paths for a particular file or a directory. I want the whole list of created symbolic links paths (location).

Example:

I created symbolic links for ~/Pictures directory on many directories. How do I list all the symlinks to that ~/Pictures directory?

Is that possible? If yes, then how?

share|improve this question
    
You need to search exhaustive, there is no count stored like there is for hard-links. See one of the answers using find. – ctrl-alt-delor Mar 4 '14 at 12:33
up vote 37 down vote accepted

Here is an example:

find -L /dir/to/start -xtype l -samefile ~/Pictures

or, maybe better:

find -L /dir/to/start -xtype l -samefile ~/Pictures 2>/dev/null

to get rid of some errors like Permission denied, Too many levels of symbolic links, or File system loop detected which find throws them when doesn't have the right permissions or other situations.

  • -L - Follow symbolic links.

  • -xtype l - File is symbolic link

  • -samefile name - File refers to the same inode as name. When -L is in effect, this can include symbolic links.

share|improve this answer
    
Could the command be modified to find symbolic link that contains a path? e.g. files across the system that may link to ~/Pictures/A, ~/Pictures/A/B/C, or any files in the subdirectories of ~/Pictures> – snowbound Jan 23 '15 at 12:30
    
Also on Mac, replace -xtype with -type – snowbound Jan 23 '15 at 12:31
1  
It took me some time to figure out it is -xtype l not -xtype 1. Thought to add a comment to save someone some trouble. – Ahmed Essam Aug 10 '17 at 23:05

Very simple :

find / -lname /path/to/original/dir

Use -lname option

NOTE : Remember that symbolic links could be anywhere, which includes a remote system (if you’re sharing files), so you may not be able to locate them all.

share|improve this answer
    
Note also, if the symlink is a relative path like ../dir then it won't find the absolute /path/to/original/dir you can instead use a pattern and weed out false positives -lname \*dir – Jason S Dec 2 '17 at 20:55

Try this :

ls -i ~/

277566 Pictures

find . -follow -inum 277566 ( find directories with the same inode number )

It will display all its symbolic links paths .

share|improve this answer
1  
This will find hard links, not symbolic links. Hard links share inode numbers. symbolic links have different inode numbers. the inode of a symbolic link has a path instead of a block list. – hildred Mar 4 '14 at 17:14
    
the question didn't mention hard or soft symbolic link – nux Mar 4 '14 at 19:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.