What is the difference between a hard link and a symbolic link?

A hard link vs a Symbolic link
ln TARGET LINK_NAME
$ ln test.txt hard_link_test.txt
$ ls -li
786433 -rw-r--r-- 2 edu edu 0 jun 21 21:27 hard-link-test.txt
786433 -rw-r--r-- 2 edu edu 0 jun 21 21:27 test.txt
$ chmod u+x test.txt
$ ls -li
786433 -rwxr--r-- 2 edu edu 0 jun 21 21:27 hard-link-test.txt
786433 -rwxr--r-- 2 edu edu 0 jun 21 21:27 test.txt
$ ln -s TARGET LINK_NAME
$ ln -s test.txt sym-link-a-test.txt
$ ls -l
lrwxrwxrwx 1 edu edu 8 jun 21 19:28 sym-link-a-test.txt -> test.txt
-rw-r--r-- 1 edu edu 0 jun 21 19:28 test.txt
$ ls -li
26547710 lrwxrwxrwx 1 edu edu 8 jun 21 19:28 enlace-simbolico-a-test.txt -> test.txt
26545137 -rw-r--r-- 1 edu edu 0 jun 21 19:28 test.txt
  • A hard link is an additional name of the original file that references inode to access the target file. In contrast, the soft link is distinct from the original file and is an alias of the original file but does not use inode.
  • When an original file is deleted, the flexible link is invalidated, whereas a physical link is valid even if the target file is deleted.
  • In Linux, the command used for hard link creation is “ ln “. In contrast, the command used for a soft link is “ln -s”.
    - hard links:
    $ ln test.txt hard_link_test.txt
    - symbolic links:
    $ ln -s TARGET LINK_NAME
  • The physical link has the same inode number different from the flexible link, where the target file and its flexible link have a different inode number.
  • Physical links are restricted to their own partitions, but flexible links can cover different file systems.
  • The performance of the hard link is better than the flexible link in some cases.
  • Relative path and absolute path are allowed in soft links. In contrast, relative path is not allowed in a hard link.

--

--

--

Electronic Engineer who loves programming

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

READ/DOWNLOAD#] Audi TT Service Manual: 2000, 2001, 2002, 2003, 2004, 2005, 2006 (Audi Service…

Get Cloudflare IP Address Ranges in Terraform Without Authentication

10 Best Online Courses to learn Spring Framework in 2022

best Spring Framework Courses for Java Developers

Speeding up SSH connection in WSL2

The DevOps Scoreboard

Eclipse Shortcut to get rid of all unused Imports in a Java file

Eclipse Shortcut to get rid of all unused Imports in a Java file

Using Lambda in Ruby

Client key binding

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Eduardo Herrera Forero

Eduardo Herrera Forero

Electronic Engineer who loves programming

More from Medium

Software Development Manifesto: The Unwritten Rules of Software Development

Any TSP, Thrift Savings Plan, 401(k) 403B 457 all work in a very similar manner.

Children life with a smartphone in the virus era

Crude Oil Prices: Petrol and Diesel Prices