Hard link vs Symbolic link
In a Linux file system , a link is a connection between a file name and the
actual data on the disk. There are two main types of links that can be created:
“hard” links, and “soft” or symbolic links.
Hard links refer to the specific location of physical data.
Symbolic link (also symlink or soft link) Refer to a symbolic path indicating
the abstract location of another file.
How to create symbolic link/hard link
Soft links are created with the ln command. For example, the following
would create a soft link named school_project to a file named project_linked,
both in the current directory
$ ln -s school_project project_linked
Sample output
The syntax is as follows to create a hard link named sh_pr_hard_linked to a file named school_project:
$ ln school_project sh_pr_hard_linked
Sample output
After creating the symbolic link, it may generally be treated as an alias for the
target. Any file system management commands (e.g., cp
, rm
) may be used
on the symbolic link. Commands which read or write file contents will access
the contents of the target file. The rm
(delete file) command, however,
removes the link itself, not the target file. Likewise, the mv
command moves
or renames the link, not the target.
Hard links limitations
There are some issues with hard links that can sometimes make them
unsuitable. First of all, because the link is identical to the thing it points to, it
becomes difficult to give a command such as “list all the contents of this
directory recursively but ignore any links”. Most modern operating systems
don’t allow hard links on directories to prevent endless recursion. Another
drawback of hard links is that they have to be located within the same file
system, and most large systems today consist of multiple file systems.