Hard and Soft Links Flashcards
The In command creates two…?
distinct types of links.
Hard links assign multiple…?
dentries (filenames) to a single inode.
Soft links are …?
distinct inodes that reference other filenames.
Linux users want the same file to exist two separate places, or have two different names. One approach is by…?
creating a hard link.
(Suppose elvis and blondie are collaborating on a duet. They would both like to be able to work on the lyrics as time allows, and be able to benefit from one another’s work. Rather than copying an updated file to one another every time they make a change, and keeping their individual copies synchronized, they decide to create a hard link.)
(Blondie has set up a collaboration directory called ~/music, which is group owned and writable by members of the group music. She has elvis do the same. She then creates the file ~/music/duet.txt, chgrps it to the group music, and uses the ln command to link the file into elvis’s directory.)
(Because the file was linked, and not copied, it is the same file under two names. When elvis edits /home/elvis/music/duet.txt, he is editing /home/blondie/music/duet.txt as well.)
How are hard links implemented?
When created, the file /home/blondie/music/duet.txt consists of a dentry, an inode, and data, as illustrated below.
See Figure 2.1. Regular File and Figure 2.2. Hardlink and Figure 2.3. Hard link after half is removed.
https://academy.redhat.com/courses/rha030-6.1/rha030_fsmngt_links.html
At a low level, the rm command is not said to delete a file, but “unlink” it. A file (meaning the file’s inode and data) are automatically deleted from the system when its link count goes to…?
0 (Implying that there are no longer any dentries (filenames) referencing the file).
The other approach to assigning a single file two names is called a …?
softlink (While superficially similar, soft links are implemented very differently from hard links.
How are soft links implemented?
When created, the file tuesday.txt, like most files, consists of a dentry, an inode, and data, as illustrated below. When the soft link today.txt was created, the soft link (unlike a hard link) really is a new file, with a newly created inode. The link is not a regular file, however, but a symbolic link. Symbolic links, rather than storing actual data, store the name of another file. When the Linux kernel is asked to refer to the symbolic link, the kernel automatically resolves the link by looking up the new filename. The user (or really, the process on behalf of the user) that referred to the symbolic link doesn’t know the difference.
Creating Links with the ln Command…?
both hard links and soft links are created with the In command.
ln [OPTION…]TARGET[LINK]
Create the link LINK referencing the file TARGET.
ln [OPTION…] TARGET… [DIRECTORY]
Create link(s) to the file(s) TARGET in the directory DIRECTORY.
ln Switch:
-f, –force…?
Clobber existing destination files.
ln Switch:
-s, –symbolic…?
make symbolic (soft) link instead of hard link.
The ln command behaves very similarly to the cp command: if the last argument is a directory, the command creates links in the …?
Specified directory which refer to (and are identically named) to the preceding arguments. Unlike the cp command, if only one argument is given, the ln command will effectively assume a last argument of “.”.
When specifying links, the ln command expects the name of the …?
original file(s) first, and the name of the link last. Reversing the order doesn’t produce the desired results. Again when it doubt, recall the behavior of the cp command.