Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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. –  richard Mar 4 at 12:33

3 Answers 3

up vote 16 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

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
    
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 at 17:14
    
the question didn't mention hard or soft symbolic link –  nux Mar 4 at 19:19

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

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.