QuestionQ132

Essential Commands

Attempting to create a hard link to a regular file results in an error. What is the most likely explanation for this failure?

  • A The source file is hidden.
  • B The source file is read-only.
  • C The source file is a shell script.
  • D The source file is already a hard link.
  • E The source and the target are on different filesystems.
Explanation

A hard link is an additional directory entry referencing the same inode as the original file, and inode numbers are only valid within the boundaries of a single filesystem. Consequently, the ln command cannot create a hard link when the source file and the target link location reside on different filesystems (e.g., different partitions or mounted devices) — it fails with an "Invalid cross-device link" error. In such cases, a symbolic link (ln -s) must be used instead. Attributes such as the file being hidden, read-only, a shell script, or already having existing hard links do not prevent hard link creation.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!