Lect5 Hardlink Softlink
Lect5 Hardlink Softlink
Filesystem Links
C2 General
Introduction
● A link is a way to make a file's data accessible via more than one
filename.
C2 General
Soft Links
● Also called Symbolic Links.
● Soft links are a file type designed to point to another file using a path
name.
C2 General
Soft Links
● Soft links are excellent for creating "shortcuts”.
C2 General
Soft Links
● To create a soft link file, use the ln command with the -s option.
ln -s target link_name
C2 General
Hard Links
● Hard links are two or more files that share the same inode number.
o Inode number: index node – contains file info including location on the disk.
● Hard links are exactly identical to the original in every way except the file
name
● Hard links are created using the ln command without using the -s option
ln target link_name
C2 General
Hard Links
● Hard links identified using ls –l.
sysadmin@localhost:~$ ls -l profile.txt
-rw-r--r-- 2 sysadmin sysadmin 110 Apr 24 16:24 profile.txt
● The link count (2) indicates how many hard links there are to the file.
● Since hard links share the same inode, they will have the same inode
number.
● The ls -i option can be helpful to validate that the files are sharing an
inode:
sysadmin@localhost:~$ ls -li profile.txt myprofile.txt
95813671 -rw-r--r-- 2 sysadmin sysadmin 110 Apr 24 16:24 myprofile.txt
95813671 -rw-r--r-- 2 sysadmin sysadmin 110 Apr 24 16:24 profile.txt
C2 General
Soft Links vs Hard Links
● Advantages of Hard links:
● Hard linked files are indistinguishable by programs from regular files
● If files are hard linked then they are always contained within one filesystem
● Removing hard links doesn't remove the actual data unless you remove all of the
hard links
C2 General
Soft Links vs Hard Links
● Advantages of Soft links:
● Soft links can be made to a directory file; hard links can not.
● Soft links can be made from a file on one filesystem to a file on another
filesystem; hard links can not.
● Soft links are very visual because the output of the ls -l command displays which
file the soft link is pointing to.
C2 General