-->

What is Soft Links and Hard Links in Linux File System

Author Piyush Gupta

To make links between files you need to use ln command. A symbolic link (also known as a soft link or symlink) consists of a special type of file that serves as a reference to another file or directory. Unix/Linux like operating systems often uses symbolic links.

Two types of links

There are two types of links
  • symbolic links: Refer to a symbolic path indicating the abstract location of another file
  • hard links : Refer to the specific location of physical data.

How do I create soft link / symbolic link?

Soft links are created with the ln command. For example, the following would create a soft link named link1 to a file named file1, both in the current directory
$ ln -s file1 link1
To verify new soft link run:
$ ls -l file1 link1
Use following command to create a soft link of Apache configuration file under /etc directory. While creating softlink of file inode number will be different that original file.
ln -s /etc/httpd/conf/httpd.conf /etc/httpd.conf
Check soft link and original file inode number.
ls -li /etc/httpd/conf/httpd.conf /etc/httpd.conf

4035744 lrwxrwxrwx 1 root root 19 Sep 19 18:19 /etc/httpd.conf -> /etc/httpd/conf/httpd.conf
6130556 -rw-r--r-- 1 root root 19 Sep 19 18:59 /etc/httpd/conf/httpd.conf

How do I create Hard link?


Use following command to create a hard-link of Apache configuration file under /etc directory. While creating hard-link of file inode number will be same as original file.
ln /etc/httpd/conf/httpd.conf /etc/httpd.conf
Check soft link and original file inode number.
ls -li /etc/httpd/conf/httpd.conf /etc/httpd.conf

6130556 -rw-r--r-- 2 root root 19 Sep 19 18:19 /etc/httpd.conf
6130556 -rw-r--r-- 2 root root 19 Sep 19 18:59 /etc/httpd/conf/httpd.conf

No comments:

Post a Comment