LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-23-2010, 01:48 PM   #1
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Rep: Reputation: 59
Identifying Links to a file


How do we check as to how many links have been created that point to a particular file?


Let's say there is this file /work/contacts.dat

and we have, let's say, 10 soft links that have been created by different users in their home directories. Now how can I figure by looking at the file /work/contacts.dat that there are 10 (soft or hard)links pointing to this particular file so that I know that it is being used or refered to by those many users and before deleting it I can check with them.
 
Old 12-23-2010, 01:53 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
You can see the number of hard links using ls -l
Code:
$ ls -lh test.txt
-rw-r--r-- 1 user1 user1 300K 2010-11-03 08:44 test.txt
The number between the permissions and the owner is the number of hard links. The above example shows that the file test.txt has one hard link pointing to it.

The only way to find the soft links would be to perform an exhaustive search of the entire file system.

Last edited by stress_junkie; 12-23-2010 at 01:54 PM.
 
Old 12-23-2010, 01:58 PM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by stress_junkie View Post
The only way to find the soft links would be to perform an exhaustive search of the entire file system.
Actually all the file systems which can contain symlinks which (not tested) you could do with find / -L -samefile <your file>

Last edited by catkin; 12-23-2010 at 02:02 PM. Reason: Added missing /
 
Old 12-23-2010, 02:01 PM   #4
devUnix
Member
 
Registered: Oct 2010
Posts: 606

Original Poster
Rep: Reputation: 59
Quote:
Originally Posted by stress_junkie View Post
You can see the number of hard links using ls -l
Code:
$ ls -lh test.txt
-rw-r--r-- 1 user1 user1 300K 2010-11-03 08:44 test.txt
The number between the permissions and the owner is the number of hard links.
I knew it but was not sure whether the number would indicate total links hard and soft or only hard or only soft. Thanks for the answer!
 
  


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
web page/links links/links vendtagain Linux - Newbie 2 09-19-2009 09:13 PM
using apache file viewer / webdav, logical links and cifs file system zerobane Linux - Server 0 03-23-2009 12:10 PM
Need help identifying the lines of Grub.conf file Sarge_P Linux - Newbie 5 09-25-2006 02:03 PM
finding links to a file bigearsbilly Solaris / OpenSolaris 2 02-10-2006 03:42 AM
Open file handles - identifying locks KimVette Linux - General 2 09-24-2005 12:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 10:34 AM.

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
Open Source Consulting | Domain Registration