Symlinks & Hardlinks

 

Symlinks & Hardlinks:

 

Q1. What is link?

Files are arranged in directories. File are found in series of directories and subdirectories. Sometime same files are found by different names inside directory or subdirectories which is known as links in Unix and linux systems.

 

Q2. How many types of links can be setup?

There are two types of links which can se setup.

 

Q3. What is hard link?

A Hard Link is where a file has two names which are both on an equal weighting, and both of the file names in the “inode table” point directly to the blocks on the disc that contain the data.

We set up a hard link with an ln command without options – if the file ab.txt already exists and we want to give an additional name (hard link) to it, we’ll write

ln ab.txt test.txt

The only way you’ll know that there’s a link there is by doing a long listing and you’ll see a link count of 2 rather than 1, and if you need to find out what’s linked to what, use the -i option to ls.

Q4. What is symbolic link?

A Symbolic Link is where a file has one main name, but there’s an extra entry in the file name table that refers any accesses back to the main name. This is slightly slower at runtime that a hard link, but it’s more flexible and much more often used in day to day admin work.

Symbolic links are set up using the ln command with the -s option – so for

example

ln -s ab.txt cd.txt

Will set up a new name cd.txt that points to the (existing) file ab.txt. If we do a log listing (ls -l) of a directory that contains a symbolic link, we’ll be told that it’s a symbolic link with an “l” in the first column, and we’ll be told where the file links to in the file name column. Veryeasy to spot!

Q5. What is difference between Soft Link and Hard link.

Soft Links(Symbolic Links) :

1.Links have different inode numbers.

2.ls -l command shows all links with second column value 1 and the link points to original file.

3. Link has the path for original file and not the contents.

4.Removing soft link doesn’t affect anything but removing original file the link becomes dangling link which points to nonexistant file. In Softlink Inode is diff and the linked file will b a shortcut of first file.

 

Hard Links :

  1. All Links have same inode number.

      2.ls -l command shows all the links with the link column(Second) shows No. of links.

  1. Links have actual file contents

      4.Removing any link just reduces the link count but doesn’t affect other links. In Hardlink Inode is same and both are independent

Q6. What permission does symlink file have ?

Symlink files always have 777 perm

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s