There are two types of links in the Linux world that you'll come across - hard links and soft links. Hard links are the source files in a different location (think, a wormhole bending space and time and being at two places at once), whereas soft links(or symbolic links) act as pointers to the original file.
Let's create a text file for experimenting called 1.txt
$ echo "1" > 1.txt
$ echo "1 again" >> 1.txt
$ cat 1.txt
1
1 again
Syntax: ln [-s] source_file link_file
Next, let's create hard and soft links to the 1.txt
file we just created.
$ ln 1.txt 1_link_hard
$ ln -s 1.txt 1_link_soft
$ ls -li 1*
554153 -rw-rw-r-- 3 nitin nitin 0 Nov 8 18:37 1_link_hard
531592 lrwxrwxrwx 1 nitin nitin 5 Apr 30 22:17 1_link_soft -> 1.txt
554153 -rw-rw-r-- 3 nitin nitin 0 Nov 8 18:37 1.txt
We notice a few things:
l
in the permissions section.->
) pointing to the source.$ cat 1_link_hard
1
1 again
$ cat 1_link_soft
1
1 again
Everything looks normal, moving on.
$ echo "1 from hard_link" >> 1_link_hard
$ echo "1 from soft link" >> 1_link_soft
$ cat 1.txt
1
1 again
1 from hard_link
1 from soft link
Everything looks normal, moving on.
$ rm 1.txt
$ ls -l
-rw-rw-r-- 3 nitin nitin 0 Nov 8 18:37 1_link_hard
lrwxrwxrwx 1 nitin nitin 5 Apr 30 22:17 1_link_soft -> 1.txt
$ cat 1_link_soft
cat: 1_link_soft: No such file or directory
$ cat 1_link_hard
1
1 again
1 from hard_link
1 from soft link
This is where a hard link stands out from a soft link. The soft link dies the moment the source is gone leaving behind a corpse (a dead link that points to nowhere), but a hard link lives on even after the source is deleted.
Hard links:
Soft links:
Download the official 2buntu app for both Android and Ubuntu Touch.