finding links to a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding links to a file
# 1  
Old 04-05-2008
finding links to a file

I am writing a shell script that needs to files that are links to on specific shell script.

e.g.

/usr/bin/a.sh

/home/mydir/a.sh --> /usr/bin/a.sh
/home/yourdir/a.sh --> /usr/bin/a.sh
/home/hisdir/a.sh --> /usr/bin/a.sh
/home/herdir/a.sh --> /usr/bin/a.sh

I know I can set myself at the /home and "find" the links, but my question is more to the guru types. Is there a simple command that I can use on /usr/bin/a.sh to get the list of all the files that have links to it?
It might give output like:

# lnk2file /usr/bin/a.sh
/home/mydir/a.sh
/home/yourdir/a.sh
/home/hisdir/a.sh
/home/herdir/a.sh
#

Just want to know if there is a better way to skin this cat.

TIA

hagar
# 2  
Old 04-06-2008
If you think about how links are implemented, I would say the generic answer is no. Hard links are just directory entries in different places which link to the same inode number; there is no link in the other direction. Similarly, symbolic links are typically just a text snippet which says where to link to, and a special flag in the directory entry tells the kernel to read the file and redirect to the file pointed to by the text snippet. Again, there is no link in the other direction.
# 3  
Old 04-06-2008
Thank you for the new knowledge you have given me re: how links actually work.

hagar
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. AIX

List all the soft links and hard links

Hi I'm logged in as root in an aix box Which command will list all the soft links and hard links present in the server ? (2 Replies)
Discussion started by: newtoaixos
2 Replies

2. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

3. Shell Programming and Scripting

Finding and replacing links

Hi, I would like to do a scripting for finding the links based on the name I have and replace the links with the new name. General find command lists everything for that links ( means all the sub-sirs and all the files), i need only the main link and replace. Can you anyone give me some... (1 Reply)
Discussion started by: rrb2009
1 Replies

4. UNIX for Dummies Questions & Answers

Showing a file's symbolic links

ls -l shows the number of links for each file. Is there a command that will show the link sources for a specific file? Running find on the entire filesystem and doing a little Perl "magic" is the only method I'm aware of. I'm running SunOS 5.8. Thanks. (6 Replies)
Discussion started by: effigy
6 Replies

5. UNIX for Dummies Questions & Answers

Listing all links in a file system

How would one find and list all links in a file system? My situation is that I built several servers for disaster recovery, mirror images of several servers in our main location. Instead of doing a "ls -l" on every file system down the /usr structor to verify that I have all the necessary links... (3 Replies)
Discussion started by: ruger14
3 Replies

6. Shell Programming and Scripting

How to get all the links of a file?

Hi all, I have several links to a file. Is there any command or anyway to get all those links. Thanks in advance -Chanakya (3 Replies)
Discussion started by: Chanakya.m
3 Replies

7. UNIX for Dummies Questions & Answers

Symbolic Links for a File

how do i get the list of symbolic link names for a particular file programatically (4 Replies)
Discussion started by: b_u_n_1234
4 Replies

8. UNIX for Dummies Questions & Answers

Finding symbolic links

How can I find all symbolic links across the network to a directory (2 Replies)
Discussion started by: mehtad
2 Replies
Login or Register to Ask a Question