LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-16-2005, 08:26 AM   #1
Akhran
Member
 
Registered: Aug 2005
Distribution: Debian 'lenny'
Posts: 208

Rep: Reputation: 30
How to find all symbolic links pointing to a particular file?


Is there a way to find all symbolic links pointing to a particular file? Eg. /test/filea -> /etc/init.d/testfile
/bin/fileb -> /etc/init.d/testfile
/etc/init.d/rC.d/filec -> /etc/init.d/testfile

filea, fileb and filec are symbolic links all pointing to the same file /etc/init.d/testfile. Is there any command to find all the symbolic links (filea, fileb and filec in this case)that are pointing to testfile?

Thanks !
 
Old 11-17-2005, 06:24 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,877

Rep: Reputation: 350Reputation: 350Reputation: 350Reputation: 350
There is a utility called symlinks. I used it a few years ago in another distro. I don't know if it's still available. It searched for all symlinks depending on the search filter the user chose. It could find dangling symlinks ( links to files no longer on the disk) or show all symlinks. You could probably pipe the output through sort to refine the output.

There may also be other utilities. www.google.com/linux is your friend. Use it.
 
Old 11-17-2005, 07:42 AM   #3
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
You can use 'find' for these purpose. Say you want to find all symlinks, which
points to the /usr/local/myfile, all over your root FS.
Code:
find / -mount -lname /usr/local/myfile
Say you want all symlinks, which points to one of the files within /usr/local
directory, regardless to which one exactly.
Code:
find / -mount -lname /usr/local/\*
We need in a backward slash before the asterix for shell (e.g. bash) do not
substitute it with anything.
For polishing the output up:
Code:
find / -mount -lname /usr/local/\* -exec ls --color=always {} \;
Hope it helps.
 
Old 11-19-2005, 01:18 AM   #4
Akhran
Member
 
Registered: Aug 2005
Distribution: Debian 'lenny'
Posts: 208

Original Poster
Rep: Reputation: 30
working directory : /etc/
lrwxrwxrwx 1 root root 15 2005-11-06 10:35 S19slapd -> ../init.d/slapd

When I do a find with
Code:
find / -mount -lname /etc/init.d/slapd
there is no result returned.


Quote:
Originally posted by Ygrex
You can use 'find' for these purpose. Say you want to find all symlinks, which
points to the /usr/local/myfile, all over your root FS.
Code:
find / -mount -lname /usr/local/myfile
Say you want all symlinks, which points to one of the files within /usr/local
directory, regardless to which one exactly.
Code:
find / -mount -lname /usr/local/\*
We need in a backward slash before the asterix for shell (e.g. bash) do not
substitute it with anything.
For polishing the output up:
Code:
find / -mount -lname /usr/local/\* -exec ls --color=always {} \;
Hope it helps.
 
Old 11-19-2005, 04:36 AM   #5
titopoquito
Senior Member
 
Registered: Jul 2004
Location: Lower Rhine region, Germany
Distribution: Slackware 14.1 (32 and 64 bit)
Posts: 1,594

Rep: Reputation: 124Reputation: 124
Ygrex' solution works here.

Code:
$ find / -mount -lname /usr/libexec/rmt
/etc/rmt
/sbin/rmt
Are you sure that / and /etc are on the same partition? Else the -mount option would of course prevent the find command to dig into /etc. Maybe try it without -mount ?
 
Old 11-19-2005, 07:25 AM   #6
Ygrex
Member
 
Registered: Nov 2004
Location: Russia (St.Petersburg)
Distribution: Debian
Posts: 666

Rep: Reputation: 68
Quote:
Originally posted by Akhran
working directory : /etc/
lrwxrwxrwx 1 root root 15 2005-11-06 10:35 S19slapd -> ../init.d/slapd

When I do a find with
Code:
find / -mount -lname /etc/init.d/slapd
there is no result returned.
Of course, if you 'ls -l' that symlink you will learn that it does not points
to the /etc/init.d/slapd directly, but ../init.d/slapd. It is why your command
is wrong. Search either for \*slapd\* or for ../init.d/slapd and it will work.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
symbolic links durden2.0 Linux - Newbie 6 11-12-2008 04:06 AM
How to search for files that are symbolic links pointing to a particular file? Akhran Linux - Newbie 1 10-13-2005 08:32 AM
How can I find symbolic links rickh Debian 2 05-26-2005 10:06 AM
how to use Find Command for Symbolic links nofunyet Linux - Newbie 2 04-08-2005 04:52 AM
Symbolic Links petercool Linux - General 2 08-20-2003 12:15 PM


All times are GMT -5. The time now is 01:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration