Hard Links
In this lesson, we learn about hard links and also the reason for using unlink() to remove a file.
We now come back to the mystery of why removing a file is performed via unlink()
, by understanding a new way to make an entry in the file system tree, through a system call known as link()
. The link()
system call takes two arguments, an old pathname and a new one; when you “link” a new file name to an old one, you essentially create another way to refer to the same file. The command-line program ln
is used to do this, as we see in this example:
Press + to interact
prompt> echo hello > fileprompt> cat filehelloprompt> ln file file2prompt> cat file2hello
Try it out yourself in the terminal below. You can run all the commands in this lesson in this terminal.
Here we created a file with the word “hello” in it, and called the file file
. We then create ...