Explanation: This command creates a hard link to a.txt with the name c.txt. The new file c.txt will have the same inode number as a.txt (Inode 525385).
A hard link is a directory entry that points to the same data blocks as another file. A hard link is indistinguishable from the original file, and it shares the same inode number, permissions, ownership, and timestamps. A hard link can only be created within the same file system, and it cannot link to directories or special files. A hard link increases the link count of the file, which is the number of directory entries that refer to the file. The link count can be seen by using the ls -l command. The file is only deleted when the link count reaches zero, which means that all the hard links to the file are removed.
The ln command is used to create hard links or symbolic links. The syntax of the ln command is:
ln [options] source target
The source is the name of the existing file, and the target is the name of the new link. By default, the ln command creates a hard link, unless the -s option is used to create a symbolic link. A symbolic link is a special file that contains the path to another file or directory. A symbolic link is different from a hard link, as ithas its own inode number, permissions, ownership, and timestamps. A symbolic link can link to any file or directory, even across file systems, and it does not affect the link count of the file. A symbolic link can be identified by the ls -l command, as it shows the link name followed by an arrow and the target name.
For example, to create a hard link to a.txt with the name c.txt, use the following command:
ln a.txt c.txt
This command will create a new file c.txt that has the same inode number as a.txt (Inode 525385). The output of the ls -i command will show something like:
525385 a.txt 525385 c.txt
To create a symbolic link to a.txt with the name b.txt, use the following command:
ln -s a.txt b.txt
This command will create a new file b.txt that has a different inode number than a.txt (Inode 526053), and contains the path to a.txt. The output of the ls -i command will show something like:
525385 a.txt 526053 b.txt -> a.txt
References:
- Linux Hard and Soft Links - Linuxize
- ln(1) - Linux manual page
- How to Create Hard and Symbolic Links in Linux - How-To Geek