LPIC-1 Exam 101 Practice Questions

Linux Professional Institute LPIC-1 Exam 101 (101-500) exam preparation

LPIC-1 Exam 101 practice questions in English: 180 questions with explanations. The mock exam has 60 questions and 90 minutes.

LPIC-1 Exam 101 free question 10 / 10 · Domain 4: Devices, Linux Filesystems, Filesystem Hierarchy Standard

A directory has a file data.txt whose link count shows as 1 in ls -l. You ran ln data.txt hard.txt and ln -s data.txt soft.txt, and then ran rm data.txt. Which combination of the link count of data.txt just before rm and the result of running cat soft.txt after rm is correct?

  1. The link count is 3, and cat soft.txt can display the contents
  2. The link count is 2, and cat soft.txt cannot display the contents
  3. The link count is 2, and cat soft.txt can display the contents
  4. The link count is 3, and cat soft.txt cannot display the contents
Show the answer and explanation

Answer: B

Why this is correct
A hard link is another name for the same inode, and each one you create increases the link count by one. ln data.txt hard.txt makes the link count 2. A symbolic link is a separate file whose contents are the path name it follows, and it does not increase the link count of data.txt. Even when one name is removed with rm data.txt, hard.txt still points to the same inode, so the contents remain (link count 1). soft.txt points to the name data.txt, which no longer exists, so it is a broken link (a dangling link), and cat fails because there is no such file.

Why the other options are wrong
"The link count is 3, and cat soft.txt cannot display the contents" … The result of cat is right. What counts toward the link count is only names that point to the same inode (hard links). soft.txt only points to the name data.txt and does not increase its link count, so it is 2.
"The link count is 2, and cat soft.txt can display the contents" … The link count is right. What soft.txt holds is the string of the name data.txt, not the contents themselves. Once the name is gone, soft.txt cannot be followed, and even though the contents remain at hard.txt, they cannot be displayed through it.
"The link count is 3, and cat soft.txt can display the contents" … Both are wrong. A symbolic link does not increase the link count and is a mechanism that follows a name, so it breaks when data.txt is removed. The contents can be read from hard.txt.

When the contents disappear
The contents of a file are released when the link count becomes 0 and no process has it open. A hard link has no distinction between an 'original' and a 'copy', and if you look with ls -li, the same inode number is listed. The broken soft.txt can be followed again if you create data.txt again in the same place.

Go to the LPIC-1 Exam 101 practice app (10 free questions; purchase unlocks all questions)

See the full practice set