LinuxQuestions.org
Help answer threads with 0 replies.
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 02-05-2007, 12:07 PM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
softlinks vs hardlinks


Hi,

I read form a source that if hardlinks to a file exist, the file can not be deleted until the hardlinks are removed? I tried this in my openSUSE 10.2 installation, and to my surprise I could remove the file with hardlinks, but the hardlinks were not behaving as links at all, rather when I created a hardlink like this:

Code:
ln filename linkname
Then removed filename, the file named linkname was an exact copy of the original file, and rm gave no errors removing the original file. Rather symbolic links behaved as links, and if the original file was removed the link became invalid, rather the hardlink retained the content? So what is the difference b/w simple copy and a hardlink then?
 
Old 02-05-2007, 12:11 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,378

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
a hard link is *NOT* a copy of a file, you clearly haven't done your reading. it is *THE* same file, but with a different name in the file table. a normal file is a file with one hard link. if you use ln to add a hard link, then it is a file with two hard links. both names are equal and one does not depend on the other.
 
Old 02-05-2007, 12:18 PM   #3
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Original Poster
Rep: Reputation: 34
But if I were to delete the original file, theoretically the other file must be deleted aswell? But that was the not the behaviour I was getting
 
Old 02-05-2007, 12:30 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,378

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
you do not delete "files", you delete references (hardlinks) to spaces of disk. all the time something in the fat table references a piece of disk space, then the contents of that space is reachable as a file.
 
Old 02-06-2007, 02:05 AM   #5
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
The number of links to the contents of your file, stored on disk, is stored.
Each time a new hard link is created, this link count is increased by one.
Each time you delete a hard link, the link count is decreased by one. It's only when the link count reaches
0, that the file contents are actually marked for deletion/overwriting on the disk itself.

I suggest you also read up on inodes, if this interests you.
 
  


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
Cd image with hardlinks kvtournh Linux - Software 2 08-27-2006 05:22 AM
Lotsa hardlinks - how do I find the others? humbletech99 Linux - General 6 11-27-2005 01:27 PM
Softlinks - cannot delete dajomu Red Hat 4 08-17-2005 02:36 PM
Crappy softlinks dajomu Linux - Newbie 4 08-16-2005 03:50 PM
Proftpd + softlinks + no go? BlackRabbit Linux - Software 6 12-16-2003 08:20 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration