Linking Files: Hard Link vs. Soft Link?
Mark Hannon
markhannon at optusnet.com.au
Tue Apr 14 07:08:05 UTC 2009
Hi guys,
Just as clarification, the i-node represents the file meta-data and does not
contain 'filename' information. The filesystem maps a 'filename' to an
i-node. If multiple filenames map to the same i-node then we have the
'hardlink' you mention. Note that a file is actually only deleted from disk
when no names refer to it (the i-node actually contains a reference count of
the number of names referring to it). This means you will not delete the
file copy until *all* links are deleted so perhaps one of your fears about
hard links is not relevant.
Hard links are more common with system binaries that use the name used to
call the program with different behaviours (e.g. unzip and zipinfo are the
same file with different behaviour)
It is easier to see what is going on with symlinks so if you can afford the
disk space then why not stick with them?
Regards/Mark
-----Original Message-----
From: ubuntu-users-bounces at lists.ubuntu.com
[mailto:ubuntu-users-bounces at lists.ubuntu.com] On Behalf Of Joe Burgess
Sent: Tuesday, 14 April 2009 4:42 PM
To: Ubuntu user technical support, not for general discussions
Subject: Re: Linking Files: Hard Link vs. Soft Link?
On Tue, Apr 14, 2009 at 09:24:49AM +0300, Amichai Rotman wrote:
> Hello,
>
> I have an alphabetized file hierarchy I'd like to organize into
> categories. These are all my media files - documents, video, audio etc.
>
> I created another hierarchy containing the categories I want and linked
> the files from the main hierarchy to the relevant category, using a
soft
> link (ln -s).
>
> I realized it's a waste of space (two inodes for each file), so I
thought
> re-creating the links as hard links.
>
> My dilemmas:
>
> Is it really better? - I understand that if I hard link a file, it is
> actually the same file, and if I delete the so called link I actually
> delete the real file - might be dangerous... I know I am stating the
> obvious, but I'd like your input on this (pros and cons).
>
> Is there a way to create hard links with a GUI? - I am using KDE
3.5.10.
> Till now I've created half a dozen hard links using the ln command in
CLI,
> but it will take me forever to create all those I need....
>
> Is it possible to create a hard link to a directory somehow? - when I
use
> the ln command to link a directory, I get an error saying it is not
> possible. If that's true, the whole thing is pointless: I'd like to
create
> a directory under the category hierarchy and then hard link the files
> under it. It will still mean less inodes, but it seems to me there has
to
> be a way....
>
> Thanks!
>
> .:====================================================:.
>
> Amichai Rotman
>
> UIN#: 6401746
> Registered Linux User#: 201192 [http://counter.li.org/]
> Registered Ubuntu User #12851
> [http://ubuntucounter.geekosophical.net]
>
>
> ----------------------------------------------------------------------
> --------------------------------------
>
> PLEASE READ: http://www.gnu.org/philosophy/no-word-attachments.html
>
>
> ----------------------------------------------------------------------
> --------------------------------------
>
> .:====================================================:.
> Henny Youngman A - "I told the doctor I broke my leg in two places. He
> told me to quit going to those places."
> --
> ubuntu-users mailing list
> ubuntu-users at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
So I have always been scared of hard links just like you. As far as hard
linking directories, according to the ln man pages there is a -d flag but it
looks like it is very possible that it won't work. So you can try that out,
or you can create the directory and then write a small bash script to go
through the directory and hard link each file. It would be wonderful if ln
had a recursive flag but it doesn't. :(.
as far as hard linking vs. soft linking, I am generally a fan of soft
linking simply so that I don't delete something and it goes away in two
places, but that is just me.
Good Luck!
--
--Joe Burgess
CMU Information Systems '12
More information about the ubuntu-users
mailing list