0% found this document useful (0 votes)
31 views9 pages

Lect5 Hardlink Softlink

This document discusses filesystem links, including soft links and hard links. Soft links, or symbolic links, point to another file using a path name and do not increase the link count. Hard links share the same inode number as the original file and are indistinguishable except by name. The key differences are that soft links can point to files on other filesystems while hard links must be on the same filesystem, and soft links are visually distinguished while hard links are identical to the original file.

Uploaded by

Diana Atef
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views9 pages

Lect5 Hardlink Softlink

This document discusses filesystem links, including soft links and hard links. Soft links, or symbolic links, point to another file using a path name and do not increase the link count. Hard links share the same inode number as the original file and are indistinguishable except by name. The key differences are that soft links can point to files on other filesystems while hard links must be on the same filesystem, and soft links are visually distinguished while hard links are identical to the original file.

Uploaded by

Diana Atef
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Lecture 5

Filesystem Links

C2 General
Introduction
● A link is a way to make a file's data accessible via more than one
filename.

● There are two types of links are available:


○ Soft links
○ Hard links

C2 General
Soft Links
● Also called Symbolic Links.

● Soft links are a file type designed to point to another file using a path
name.

● Soft links are distinguishable by their file type.

● For example, a detailed listing of the /bin/systemd file shows that it is a


symbolic link:
sysadmin@localhost:~$ ls -l /bin/systemd
lrwxrwxrwx 1 root root 20 Feb 28 21:03 /bin/systemd -> /lib/systemd/systemd

lrwxrwxrwx 1 root root 20 Feb 28 21:03 /bin/systemd -> /lib/systemd/systemd

C2 General
Soft Links
● Soft links are excellent for creating "shortcuts”.

● When a system file is moved to another location by the developers,


soft links are created to make it easier for administrators and users
to find the new location.

C2 General
Soft Links
● To create a soft link file, use the ln command with the -s option.
ln -s target link_name

sysadmin@localhost:~$ ln -s file1.txt file2.txt


sysadmin@localhost:~$ ls -l file*
-rw-rw-r-- 1 sysadmin sysadmin 0 May 9 02:48 file1.txt
lrwxrwxrwx 1 sysadmin sysadmin 9 May 9 02:49 file2.txt -> file1.txt

● Soft link files do not increase the link count number associated with a


regular file.
-rw-r--r-- 1 sysadmin sysadmin May 9 14:39 file1.txt
lrwxrwxrwx 1 sysadmin sysadmin May 9 14:39 file2.txt -> file1.txt

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

● It is easy to find files that are hard linked

● 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

You might also like