Friday 2 August 2019

Hard linking a file

Let’s take a case,
We are working on updating particular software packages on Linux machine. And unexpectedly, a couple of important files got deleted by the administrator.
During this situations, hard linked files will come handy as a backup.

Note: 
Generally, the hard link file is used for the backup purpose of small and important configuration files like /etc/passwd, /etc/shadow etc.

Command Syntax:
ln actual-file hard link-file

Example:
[root@sys2 ~]# ln abclearn hardln [root@sys2 ~]# ls -l hardln
-rw-r--r--. 2 root root 16 Jan 28 19:55 hardln

[root@sys2 ~]# ls -l abclearn
-rw-r--r--. 2 root root 16 Jan 28 19:55 abclearn

In the above-highlighted output,
We can see the properties of both files are exactly same including time stamp also.
Best practice,
Creating hard links for the important files is always the best practice.

Important point to remember about hard links:
  • It is a permanent link to the original file.
  • Hard Link file size and original file size is same.
It means, any changes made to actual file content will be updated in hard link file also.We don’t have to again go and edit it.
  • Inode number is same for both original and hard link file.

0 comments:

Post a Comment