Hard and Soft Links Flashcards

1
Q

The In command creates two…?

A

distinct types of links.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Hard links assign multiple…?

A

dentries (filenames) to a single inode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Soft links are …?

A

distinct inodes that reference other filenames.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Linux users want the same file to exist two separate places, or have two different names. One approach is by…?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How are hard links implemented?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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…?

A

0 (Implying that there are no longer any dentries (filenames) referencing the file).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The other approach to assigning a single file two names is called a …?

A

softlink (While superficially similar, soft links are implemented very differently from hard links.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How are soft links implemented?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Creating Links with the ln Command…?

A

both hard links and soft links are created with the In command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

ln [OPTION…]TARGET[LINK]

A

Create the link LINK referencing the file TARGET.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

ln [OPTION…] TARGET… [DIRECTORY]

A

Create link(s) to the file(s) TARGET in the directory DIRECTORY.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

ln Switch:

-f, –force…?

A

Clobber existing destination files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

ln Switch:

-s, –symbolic…?

A

make symbolic (soft) link instead of hard link.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The ln command behaves very similarly to the cp command: if the last argument is a directory, the command creates links in the …?

A

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 “.”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

When specifying links, the ln command expects the name of the …?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Soft links are susceptible to a couple of problems that hard links are not. The first is called dangling links… Example:

A

The symbolic link today.todo still references the file tuesday.todo, but the file tuesday.todo no longer exists! When madonna tries to read the contents of today.todo, she is met with an error.

Figure 2.5 Dangling Links.

https://academy.redhat.com/courses/rha030-6.1/rha030_fsmngt_links.html

17
Q

The second problem with soft links is that symbolic links are susceptible to its recursive links. In day to day use, recursive links are not nearly as common almost has to be looking for them to create them. Examples:

A

What if madonna created two symbolic links, link_a, which referenced a file named link_b, and link_b, which references the file link_a, as illustrated in figure 2.6.

https://academy.redhat.com/courses/rha030-6.1/rha030_fsmngt_links.html

18
Q

When creating soft link to be used, and when should a hard link be used…?

A

Generally, hard links are more appropriate if both instances of the link have a reasonable use, even if the other instance didn’t exist. In the example above, even if blondie decided not to work on the duet and removed her file, elvis could reasonably continue to work. Soft links are generally more appropriate when one file cannot reasonably exist without the other file. In the example above, madonna could not have tasks for “today” if she did not have tasks for “tuesday”. These are general guidelines, however, not hard and fast rules.

Sometimes, more practical restrictions make the choice between hard links and soft links easier. The following outlines some of the differences between hard and soft links. Do not be concerned if you do not understand the last two points, they are included for completeness.

19
Q

Directories may not be …?

A

hard linked.

20
Q

Hard links have no concept of …?

A

“original” and “copy”. Once a hard link has been created, all instances are treated equally.

21
Q

Hard links must refer to files in…?

A

the same filesystem.

22
Q

Hard links may be shared between..?

A

“chroot”ed directories.

23
Q

Soft links may refer to …?

A

directories.

24
Q

Soft links have a concept of “referrer” and “referred”. Removing the “referred” file results in…?

A

a dangling referrer.

25
Q

Soft links may span….?

A

filesystems (partitions)

26
Q

Soft links may not refer to files…?

A

outside of a “chroot”ed directory.

27
Q

n her home directory, blondie has a file called rhyme and a directory called stuff. She takes a long listing with ls -li, where the -i command line switch causes the ls command to print the inode number of each file as the first column of output.
Because each inode in a filesystem has a unique inode number, the inode number can be used to…?

A

identify a file. In fact, when keeping track of files internally, the kernel usually refers to a file by inode number rather than filename.
See https://academy.redhat.com/courses/rha030-6.1/rha030_fsmngt_links_examples.html