System Calls in Linux
Last updated
Last updated
Hard Links: In the Linux operating system, a hard link is equivalent to a file stored in the hard drive – and it actually references or points to a spot on a hard drive. A hard link is a mirror copy of the original file.
Every file on the Linux filesystem starts with a single hard link. The link is between the filename and the actual data stored on the filesystem. When changes are made to one filename, the other reflects those changes. The permissions, link count, ownership, timestamps, and file content are the exact same. If the original file is deleted, the data still exists under the secondary hard link. The data is only removed from your drive when all links to the data have been removed. If you find two files with identical properties but are unsure if they are hard-linked, use the ls -i
command to view the inode number. Files that are hard-linked together share the same inode number.
$ ln link_test /tmp/link_new
[tcarrigan@server demo]$ ls -l link_test /tmp/link_new
-rw-rw-r--. 2 tcarrigan tcarrigan 12 Aug 29 14:27 link_test
-rw-rw-r--. 2 tcarrigan tcarrigan 12 Aug 29 14:27 /tmp/link_new
Soft Links: Commonly referred to as symbolic links, soft links link together non-regular and regular files. They can also span multiple filesystems. By definition, a soft link is not a standard file, but a special file that points to an existing file.
ln -s /home/tcarrigan/demo/soft_link_test /tmp/soft_link_new
[tcarrigan@server demo]$ ls -l soft_link_test /tmp/soft_link_new -rw-rw-r--. 1 tcarrigan tcarrigan 17 Aug 30 11:59 soft_link_test lrwxrwxrwx. 1 tcarrigan tcarrigan 35 Aug 30 12:09 /tmp/soft_link_new -> /home/tcarrigan/demo/soft_link_test
inodes: On the filesystem, each file is identified by a unique number (an inode number). The link system call just creates another name in the filesystem with the same inode.
When you open a file htrough an application, it points to inode which points to data on the disk and that's how a file is opened and operated upon.