Working with Links
Learn how to use links to make shortcuts in a filesystem.
We'll cover the following...
Sometimes, it’s helpful to create a shortcut to a file. For example, we may want to keep a configuration file in an easy-to-access location, but a piece of software expects to find that file in a specific location. We can use links to create shortcuts to files.
Looking at inodes
When we create a file, we’re creating a link to an
greetings.txt
that contains some text:
$ echo "Hi there!" > greetings.txt
Now, we use the ls -i
command to look at the inode associated with the file:
$ ls -i greetings.txt
The number that can be seen next to the file name is the inode number associated with the file.
We can create two types of shortcuts, or links, to files. The first type is hard links, which are pointers to the actual inode. The second is symbolic links, or symlinks, which are links to another file. Hard links only work for files, whereas symbolic links work for files and directories.
Let’s look at hard links first. Using the ln
command, we create a hard link called salutations
that points to greetings.txt
:
$ ln greetings.txt salutations
Run the complete code on the terminal below for practice.
echo "Hi there!" > greetings.txt
clear
ln greetings.txt
...