Symbolic links and Hard link in UNIX
Welcome to my blog, today i will talk about the links, hard and soft links in Linux.
A link by definition "is a pointer to a file. Like pointers in any programming languages, links in UNIX are pointers pointing to a file or a directory. Creating links is a kind of shortcuts to access a file. Links allow more than one file name to refer to the same file, elsewhere".
In Unix we can find two types of links, the soft (or symbolic) links and the hard links.
There are two types of links, Soft Link or Symbolic links and Hard links. These links have a different behavior depending on the case. The hard link connects directly to the inode so if always refer to the source, even if moved or removed. Symbolic links are like the shortcuts in windows, if you remove the source, the symbolic link is broken.
For example, if we have a file a.txt. If we create a hard link to the file and then delete the file, we can still access the file using hard link. But if we create a soft link of the file and then delete the file, we can’t access the file through soft link and soft link becomes dangling. Basically hard link increases reference count of a location while soft links work as a shortcut (like in Windows)
How to create hard and soft links:
1. Hard Links
$ ln [original filename] [link name]
2. Soft Links
$ ln -s [original filename] [link name]
The command ls -l (long format) shows all the links with the link column shows number of links.