Hard Links

In this lesson, we learn about hard links and also the reason for using unlink() to remove a file.

We'll cover the following...

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 > file
prompt> cat file
hello
prompt> ln file file2
prompt> cat file2
hello

Try it out yourself in the terminal below. You can run all the commands in this lesson in this terminal.

Terminal 1
Terminal
Loading...

Here we created a file with the word “hello” in it, and called the file file. We then create ...