0% found this document useful (0 votes)
45 views8 pages

Hard Links vs Soft Links in Linux

The document explains the differences between hard-links and soft-links in a Linux environment. It details how hard-links share the same inode as the original file, while soft-links create a new inode, and demonstrates the effects of modifying or deleting the original file on both types of links. The document also includes command line examples illustrating the creation and behavior of hard-links and soft-links.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views8 pages

Hard Links vs Soft Links in Linux

The document explains the differences between hard-links and soft-links in a Linux environment. It details how hard-links share the same inode as the original file, while soft-links create a new inode, and demonstrates the effects of modifying or deleting the original file on both types of links. The document also includes command line examples illustrating the creation and behavior of hard-links and soft-links.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Hard-links and Softlinks

MADHAV@DESKTOP-O3S5JRL MINGW64 ~/OneDrive/Desktop


$ ssh -i "[Link]" ec2-user@[Link]-south-
[Link]
The authenticity of host '[Link]
([Link])' can't be established.
ED25519 key fingerprint is SHA256:EN1UyNyAuouTwruxsBbE727tqS00+6TehcRzEjFWILg.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[Link]'
(ED25519) to the list of known hosts.
, #_
~\_ ####_ Amazon Linux 2023
~~ \_#####\
~~ \###|
~~ \#/ ___ [Link]
~~ V~' '->
~~~ /
~~._. _/
_/ _/
_/m/'
[ec2-user@ip-172-31-10-214 ~]$ yum update -y
Error: This command has to be run with superuser privileges (under the root user on
most systems).
[ec2-user@ip-172-31-10-214 ~]$ sudo -i
[root@ip-172-31-10-214 ~]# yum update -y
Amazon Linux 2023 Kernel Livepatch repository 257 kB/s |
26 kB 00:00
===================================================================================
======================
WARNING:
A newer release of "Amazon Linux" is available.

Available Versions:

Version 2023.9.20251020:
Run the following command to upgrade to 2023.9.20251020:

dnf upgrade --releasever=2023.9.20251020

Release notes:
[Link]
[Link]

===================================================================================
======================
Dependencies resolved.
Nothing to do.
Complete!
[root@ip-172-31-10-214 ~]# exit
logout
[ec2-user@ip-172-31-10-214 ~]$ pwd
/home/ec2-user
[ec2-user@ip-172-31-10-214 ~]$ mkdir -p ./linux-practice/links/
[ec2-user@ip-172-31-10-214 ~]$ pwd
/home/ec2-user
[ec2-user@ip-172-31-10-214 ~]$ ls
linux-practice
[ec2-user@ip-172-31-10-214 ~]$ cd ./linux-practice/links/
[ec2-user@ip-172-31-10-214 links]$ touch original
[ec2-user@ip-172-31-10-214 links]$ echo -e "Amazon\nMyntra\nFlipkart\nMeesho\nEbay\
nShopsy" >> original
[ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
[ec2-user@ip-172-31-10-214 links]$ cp -l original hard-link
[ec2-user@ip-172-31-10-214 links]$ cp -s original soft-link
[ec2-user@ip-172-31-10-214 links]$ ls -al
total 8
drwxr-xr-x. 2 ec2-user ec2-user 56 Oct 24 05:41 .
drwxr-xr-x. 3 ec2-user ec2-user 19 Oct 24 05:39 ..
-rw-r--r--. 2 ec2-user ec2-user 42 Oct 24 05:41 hard-link
-rw-r--r--. 2 ec2-user ec2-user 42 Oct 24 05:41 original
lrwxrwxrwx. 1 ec2-user ec2-user 8 Oct 24 05:41 soft-link -> original
[ec2-user@ip-172-31-10-214 links]$ echo -e "Shopclues\nSnapdeal\nAjio\nJiomart" >>
original [ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
[ec2-user@ip-172-31-10-214 links]$
[ec2-user@ip-172-31-10-214 links]$ echo -e "Swiggy\nZomato" >> hard-link
[ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
[ec2-user@ip-172-31-10-214 links]$ echo -e "Blinkit\nInstamart\nZepto\nCounty
Delight" >> soft-link
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ ls -ial
total 8
8536202 drwxr-xr-x. 2 ec2-user ec2-user 56 Oct 24 05:41 .
493569 drwxr-xr-x. 3 ec2-user ec2-user 19 Oct 24 05:39 ..
8536240 -rw-r--r--. 2 ec2-user ec2-user 127 Oct 24 05:46 hard-link
8536240 -rw-r--r--. 2 ec2-user ec2-user 127 Oct 24 05:46 original
8536255 lrwxrwxrwx. 1 ec2-user ec2-user 8 Oct 24 05:41 soft-link -> original
[ec2-user@ip-172-31-10-214 links]$ rm original
[ec2-user@ip-172-31-10-214 links]$ ls -ial
total 4
8536202 drwxr-xr-x. 2 ec2-user ec2-user 40 Oct 24 05:46 .
493569 drwxr-xr-x. 3 ec2-user ec2-user 19 Oct 24 05:39 ..
8536240 -rw-r--r--. 1 ec2-user ec2-user 127 Oct 24 05:46 hard-link
8536255 lrwxrwxrwx. 1 ec2-user ec2-user 8 Oct 24 05:41 soft-link -> original
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
cat: soft-link: No such file or directory
[ec2-user@ip-172-31-10-214 links]$

Results: When you create hard-links ad soft-links for a file.


1) Inode for hard-links remains same as of original file, but for soft-
links, a new I node gets created.

Example:
[ec2-user@ip-172-31-10-214 links]$ ls -ial
total 8

Inode permissions file-name


-----------------------------------------------------------------
8536202 drwxr-xr-x. 2 ec2-user ec2-user 56 Oct 24 05:41 .
493569 drwxr-xr-x. 3 ec2-user ec2-user 19 Oct 24 05:39 ..
8536240 -rw-r--r--. 2 ec2-user ec2-user 127 Oct 24 05:46 hard-link
8536240 -rw-r--r--. 2 ec2-user ec2-user 127 Oct 24 05:46 original
8536255 lrwxrwxrwx. 1 ec2-user ec2-user 8 Oct 24 05:41 soft-link -> original

2) If you add/remove data to/from any of the file, original or hard-


link or soft-link, the changes will be applied to the other file as well.

Example:

[ec2-user@ip-172-31-10-214 links]$ echo -e "Shopclues\nSnapdeal\nAjio\nJiomart" >>


original [ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
[ec2-user@ip-172-31-10-214 links]$
[ec2-user@ip-172-31-10-214 links]$ echo -e "Swiggy\nZomato" >> hard-link
[ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
[ec2-user@ip-172-31-10-214 links]$ echo -e "Blinkit\nInstamart\nZepto\nCounty
Delight" >> soft-link
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ cat original
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight

3) When you delete original file, hard-link remains unaffected, but


soft-link gets broken.

Example:

[ec2-user@ip-172-31-10-214 links]$ rm original


[ec2-user@ip-172-31-10-214 links]$ ls -ial
total 4
8536202 drwxr-xr-x. 2 ec2-user ec2-user 40 Oct 24 05:46 .
493569 drwxr-xr-x. 3 ec2-user ec2-user 19 Oct 24 05:39 ..
8536240 -rw-r--r--. 1 ec2-user ec2-user 127 Oct 24 05:46 hard-link
8536255 lrwxrwxrwx. 1 ec2-user ec2-user 8 Oct 24 05:41 soft-link -> original
[ec2-user@ip-172-31-10-214 links]$ cat hard-link
Amazon
Myntra
Flipkart
Meesho
Ebay
Shopsy
Shopclues
Snapdeal
Ajio
Jiomart
Swiggy
Zomato
Blinkit
Instamart
Zepto
County Delight
[ec2-user@ip-172-31-10-214 links]$ cat soft-link
cat: soft-link: No such file or directory

You might also like