Hard/Soft link in linux are basically shortcuts like in windows but there is slightly difference in linux and windows. Hard/Soft link are based on inode table in linux. Whenever we create any partition in linux there is always a separate table has been created in which stores various information like size,device id, user id etc.
Its like a data structure. Inode no is a unique identify number, whenever we create a file . inode number generates automatically. Following are the information stored in inode table :-
Its like a data structure. Inode no is a unique identify number, whenever we create a file . inode number generates automatically. Following are the information stored in inode table :-
- Size of file
- Device ID
- User ID of the file
- Group ID of the file
- The file mode information and access privileges for owner, group and others
- File protection flags
- The timestamps for file creation, modification etc
- link counter to determine the number of hard links
- Pointers to the blocks storing file’s contents
Whenever we access an file in directory we usally give a file name but internally the file name is mapped with indoe number in inode table.
To view your indoe number of a file:
#ls -li
#df -i
(To check inode table in File System)
Hard Link:
#ln
(This command is use for creating hard links in linux)
As you can see file 'x' and 'x2' have same i-node number in inode table.(Here number 2 is denoting as 2 links of file)
Hard link makes your file point to same file even if you delete the original file. You can not find out which is the original file and which is hard link by looking the file if you don't know already.
Note: Hard Links/ Soft Links never create a new file.
If you copy the file than it creates a new file and takes space in the partition.
Note: Hard link only creates in same partition.
Soft Link:
#ln -s
(-s is for soft link, soft link is similar to shortcut in windows, if you delete soft link you can not access original file.



0 comments:
Post a Comment