# Let's have some fun with hardlinks and symlinks. set -x touch file # create a test file stat file # let's check how it looks # To create a hard link, we can use the command ‹ln› (short for # link). After a hard link is created, you can no longer tell which # link is the original and which is ‘the link’: they are the same in # all respects. ln file hardlink # make ‹hardlink› refer to the same inode as ‹file› stat file # observe the link count and the inode number stat hardlink # same here # We can now unlink the original file and see what happens? rm file stat hardlink # this should be unchanged, save for link count mv hardlink file # get back to where we started (‹mv› renames files) mkdir dir ln dir dirlink # this fails, directory hardlinking is forbidden # Let's look at soft (symbolic) links now. They are created using # ‹ln -s› (where ‹s› stands for soft/symbolic): ln -s file softlink ln -s dir dirlink # Both these worked, let's look at stat: stat softlink stat dirlink # There is one more command that is interesting with regards to symlinks: readlink softlink readlink dirlink readlink dir # fails, ‹dir› is not a symlink rm -df file dir dirlink softlink # Let's look at some weird things that can happen with symlinks too: # # $ micro badlink.sh