LinuxQuestions.org
Visit Jeremy's Blog.
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 04-11-2012, 04:39 AM   #1
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Rep: Reputation: Disabled
Thumbs up Hard Links


Hi everyone,

Actually there are soft links n hard links in linux.

For suppose I have created a file and created some n number of hard links to that file and I forgot the main file which initially I created.

Now how can I find the main file ???????
 
Old 04-11-2012, 04:53 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
for hard links there IS no main file. Every file name is a link to the data, on an equal basis.

to find ALL hard links, you can use the -samefile <filename> option to "find".
 
Old 04-11-2012, 04:55 AM   #3
ravi_nandula
Member
 
Registered: Sep 2011
Posts: 81

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by acid_kewpie View Post
for hard links there IS no main file. Every file name is a link to the data, on an equal basis.

to find ALL hard links, you can use the -samefile <filename> option to "find".
you can use the -samefile <filename> option to "find".[/QUOTE]
I did not get this line...can u pls repeat it.....

Thanks for quick rply
 
Old 04-11-2012, 04:58 AM   #4
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
man find for more information.
 
Old 04-11-2012, 04:59 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959Reputation: 1959
A hardlink connects an inode to a filename. This means, in essence, that you are giving the one file two (or more) different names. There really is no "original" file, they are all the same one. When you delete the last hardlink, you delete the file itself.


You can use find to search for a file by inode, which you can get from ls -i or stat on any of the existing links. Or you can use the -samefile option.

Code:
find /topleveldir -inum "<num>" -print

find /topleveldir -samefile "<linkname>" -print

A symlink is different, being just a pointer file that sits there and redirects any access to it to the actual location of the file.

(Darnit, take a couple of minutes to double-check what I'm doing, and half-a-dozen people have beaten me to the answer. )

Last edited by David the H.; 04-11-2012 at 05:04 AM.
 
  


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
hard links why to use drManhattan Linux - Newbie 5 03-23-2011 01:02 PM
Symbolic links Vs Hard links sulekha Linux - General 2 10-02-2008 07:03 AM
technical question about hard links v soft links 7stud Linux - Newbie 2 02-23-2007 06:57 PM
links (hard links and soft links..) sachitha Programming 1 08-10-2005 12:10 PM
Sym links and hard links akudewan Linux - Newbie 4 02-09-2005 05:08 AM


All times are GMT -5. The time now is 01:07 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