How to create a hard links in Linux / UNIX

by Vivek Gite · 2 comments

Q. Both Linux / UNIX allows the data of a file to have more than one name in separate places in the same file system. Such a file with more than one name for the same data is called a hard-linked file. How do I create a hard link in Linux / UNIX?

A. A hard link to a file is indistinguishable from the original directory entry; any changes to a file are effectively independent of the name used to reference the file. Hard links may not normally refer to directories and may not span file systems.

ln command to make links

ln command make links between files. By default, ln makes hard links.

ln command syntax

ln {source} {link}

Where,
=> source is an existing file
=> link is the file to create

To create hard link for foo file, enter:
ln foo bar
ls -i foo
ls -i bar

Hard links limitations

There are some issues with hard links that can sometimes make them unsuitable. First of all, because the link is identical to the thing it points to, it becomes difficult to give a command such as "list all the contents of this directory recursively but ignore any links". Most modern operating systems don't allow hard links on directories to prevent endless recursion. Another drawback of hard links is that they have to be located within the same file system, and most large systems today consist of multiple file systems.

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 2 comments… read them below or add one }

1 zafar 10.01.09 at 2:59 am

hi i m zafar
i wanna to update in linux command
but i know some cmd so plz me update continu
thanks

2 amu 12.07.09 at 5:45 pm

hard link

ln -fs file_location link_file_location
where
fs is forcefully and source respectively

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All