How do you show hard links only?

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

How do you show hard links only?

Post by alex.barylski »

I'm confused about how hard linsk work exactly...

I have a source directory with files in it. I then made a exact mirror of all the directories using mkdir recursively. However the file contents are hard links in all the mirrored copies.

Essentially as I understand it, each hard link points to a source or original file. If the source is removed do all the hard links break or is this only the case with soft links?

Hard links are pointers to contents and a reference counting mechanism is used to detemrine when file data is removed, this I understand. So if I create a file normally it's data is already stored as a hard link and adding additional hard links just increments the counter?

Basically, if I have several files which hard link to a source, either of those edited files will be reflected through any of the other 'aliases' so to speak.

How can I tell if the file I'm editing is a hardlink or a physical copy of the original -- that is if modified it creates a branch as opposed to updating multiple copies simulatneously???

Cheers :)
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How do you show hard links only?

Post by VladSun »

Hockey wrote:If the source is removed do all the hard links break or is this only the case with soft links?
Only for soft links.
Hockey wrote:So if I create a file normally it's data is already stored as a hard link and adding additional hard links just increments the counter?
Yes
Hockey wrote:How can I tell if the file I'm editing is a hardlink or a physical copy of the original -- that is if modified it creates a branch as opposed to updating multiple copies simulatneously???
There are no "copies"... think about hardlinks as C++ references, and softlinks as pointers.

PS: Please, don't use hardlinks - they are dangerous.
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: How do you show hard links only?

Post by alex.barylski »

Hmmm...why are hard links dangerous?

Basically I have a source tree which I develop on, test, etc.

I then have copies of that source tree installed in various places for several clients. Instead of having to update each file in each separate installation what I have done is create hardlinks for each file (not directories -- just files) to essentially point to the original source, so when I make a change to the original, it's propagated throughout the other installations as well.

So your saying i should use soft links for this instead? Why?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How do you show hard links only?

Post by VladSun »

Well, *now* I'm not sure that they are dangerous ... they would be if you could create a hard link to a directory. But I tried it and it appears that it's not permitted :)

Also, don't foget to turn on FollowSymlinks in httpd.conf ;)

PS: Or even better SymLinksIfOwnerMatch
There are 10 types of people in this world, those who understand binary and those who don't
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: How do you show hard links only?

Post by alex.barylski »

As I understand, hard links cannot be used on directories, but I don't understand why that would be dangerous? Because of recursion?
Also, don't foget to turn on FollowSymlinks in httpd.conf
Hmmm...I don't use symlinks...but just curious...why?

I guess one could maybe use a symlink to gain access to private file through apache this way??? Is this what the concern would be about?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How do you show hard links only?

Post by VladSun »

Hockey wrote:As I understand, hard links cannot be used on directories, but I don't understand why that would be dangerous? Because of recursion?
For example, imagine that you created you created a hard link to a directory inside itself, and then removed the link to that directory from its parent directory. The garbage collector wouldn't see that the directory can't be accessed, since it still has links to it, but you'll be unable to remove it, since you can't access it by any name.
Hockey wrote:Hmmm...I don't use symlinks...but just curious...why?

I guess one could maybe use a symlink to gain access to private file through apache this way??? Is this what the concern would be about?
First, I do advice you to use soft links.
And if you use soft links you'll have to turn FollowSymlinks/SymLinksIfOwnerMatch on in order to have access to linked files/directories by Apache.

Read the Apache manual about the security issues of FollowSymlinks/SymLinksIfOwnerMatch :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: How do you show hard links only?

Post by Kieran Huggins »

That's a neat idea, but why not just use SVN? Then you could test away without fear of production systems breaking. An "svn up" in the client machines is quick and easy, and you also get the benefit of version control.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: How do you show hard links only?

Post by VladSun »

Using SVN (and co.) would be like "client side" sync, while using soft links would be like "server-push" sync :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply