How to Create Symbolic Link of File in Linux

Channel: Linux
Abstract: Check soft link and original file inode number. ls -li /etc/httpd/conf/httpd.conf /etc/httpd.confCheck soft link and original file inode number. ls -l
Command: ln -s /tmp/original.txt /tmp/linkfile.txtExampleCreate Soft Link

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 11 Jan 10 03:19 /etc/httpd.conf -> /etc/httpd/conf/httpd.conf
6130556 -rw-r--r-- 1 root root 24 Nov 16 11:29 /etc/httpd/conf/httpd.conf
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 24 Nov 16 11:29 /etc/httpd.conf
6130556 -rw-r--r-- 2 root root 24 Nov 16 11:29 /etc/httpd/conf/httpd.conf

You can read this tutorial to understand differences between soft link and hard link on the Linux file system.

Ref From: tecadmin

Related articles