Firstly, What is an inode and what it has to do with links in Linux?
An inode (or Index node) is a data structure in Linux File System which stores information about a file system object. Each object in file system gets an unique inode number which distinguishes it from other inodes. Every file and directory in the Linux File System has an inode number.
You can check the inode number of files and dirs of your present working dir using ls -i command.
$ ls -i
7361517 dir1 7361518 file1 7361519 test1
or use ls -lih to get a more reliability
$ ls -lih
total 28K
7361517 drwxr-xr-x 2 user user 4.0K Aug 22 13:43 dir1
7361518 -rw-r--r-- 2 user user 24 Aug 22 13:45 file1
7361519 -rw-r--r-- 1 user user 24 Aug 22 13:46 test1
To check the information stored in an inode you can use the stat command followed by the file or directory name.
NOTE: a file system object exist when it has at least 1 link which points to its inode.
“No Space Left on Device” issue
Sometimes it could happen that an operating system reposts that “No Space Left on Device”. But when you check the available space on your partition, it has a lot space available.
One of the possible reason is that the system has gone out of inodes. To confirm run df -i and will show the disk utilization of inode on the system.
This is how normally a inode usage will look like. But if your are getting the “No Space Left on Device” error then the “IUsed%” would be shown 100%. During the creation of partition, the inode limit is configured.
Links
On a Linux system you can create two types of link to a file.
Soft Link(or symbolic link)
Hard Link
Soft Link
Soft links are similar to links on a windows computer. When you want a file to be stored on a different location but able to access the file using a link on your desktop or anywhere convenient.
You can create a soft link or a symbolic link on Linux using the ln command followed by -s (for symbolic) tag and below is an example:
If you want to name the soft link the same as the source file then you can just point to the target dir without file name. But if you want the soft link to be named different then you can enter the name after the target dir.
The inode number of the soft link is different than the source file inode number.
If you the source file get deleted then the soft link becomes invalid.
Hard Link
When a hard link is created, another file get created with the same underlying inode. Which means, both the files are referencing to the same inode. If you edit any one of the files, it gets reflected on the other file as well. But if you delete any one of the file the other file does not get deleted.
You can create a hard link without using the -s tag and below is an example:
$ ln /path/to/your/file /path/to/destination/dir/
The inode number of the hard linked files are the same.
If you want to move or transfer the hard linked file on a different drive, you may have a problem as the inode number of the file may be unknown to that drive’s file system.