Hard links and soft links are like shortcuts to the file or folder you reference. A hard link is more like a duplicate file sharing the inodes or location on the hard disk. A soft link is more like a short cut.
Lets start by creating a file and viewing its inode count.
touch test
The above command creates a file named test. Now to view the inode count we can use the ls -l command on the file.
ls -l test
The output of the ls -l command will display the permissions for that file first, then the number of inode references, user, group, filesiz and last modified date and time. After the file is created you’ll see that the inode is set to 1 by default, since you only have 1 of that file.
Creating Hard Links
Hard links can only be created as long as the link is on the same partition.
ln test test2
The above command creates a new file test2 that points to the same inodes for test. If you were the run the ls -l command on either test and test2 you’d see that the number of inodes increased by 1. You could now remove the test file and it would not affect the new test2 file that you made.
Creating Soft Links
Soft links can be created across partitions but requires the original file to always stay in the same location. Creating a soft link is more like a short cut. In order to create a soft link you’d need to use the -s flag.
ln -s test test2
The above command creates a symbolic link which does not affect the inode count on the ls -l display. If you remove the test file, the test2 file will no longer be functional.
Post By: Frank Perez | Add to favorites
Leave a Comment