Important info
inodes store the following
For more information on the Linux filesystem, permissions etc, see here
The name of the file is not stored in the inode. This is stored in the directory, each file name knows which inode to address in order to access further file information. inode does not know what name it has, but does know how many names are associated with it. These names are hardlinks.
Creating a file also creates a hardlink. A file can have multiple hardlinks. There are some 'gotchas' for working with hardlinks:
No difference exists between the first hardlink and the second hardlink. Hardlinks can be deleted in any order without affecting the other hardlinks.
Symbolic links do not link to the inode, these link to the name of the file. This makes them more flexible but there are also disadvantages.
Advantages | Disadvantages |
---|---|
Can link to files on other devices | When the original file is remove, the link becomes invalid and stops working |
Can link to directories |
Symbolic links point to hardlinks:
Links are created with the ln
command. Using the same order of parameters as cp
and mv
(source then target) and use -s
to create a symbolic link.
In order to be able to create hardlinks, you must be the owner of the file (introduced in RHEL 7).
Command | Explanation |
---|---|
ln /etc/hosts . |
Creates a link to the file /etc/hosts in the current directory |
ln -s /etc/hosts . |
Creates a symbolic link to the file /etc/hosts in the current directory |
ln -s /home /tmp |
Creates a symbolic link to the directory /home in the /tmp directory |
The ls
command can reveal if a file is a link or not. In the output of ls -l