Sobes.tech
Junior — Middle

Kuidas erinevad Linuxis kõvühend ja sümboolne link ning millised on nende kasutamise omadused?

sobes.tech AI

Vastus AI-lt

A hard link and a symbolic link (symlink) are two ways to create links to files in Linux, but they differ in their working principle and application:

  • Hard link:

    • It is an additional name for an existing file.
    • It directly points to the inode of the file.
    • Multiple hard links to the same file are equal — the file exists as long as at least one link exists.
    • You cannot create a hard link to a directory (to avoid cycles).
    • You cannot create a hard link to a file on another partition or device.
  • Symbolic link:

    • It is a separate file containing the path to another file or directory.
    • It can point to directories and files on other partitions.
    • If the target file is deleted, the symbolic link becomes "broken" (no longer works).

Usage example:

# Create a hard link
ln original.txt hardlink.txt

# Create a symbolic link
ln -s /path/to/original.txt symlink.txt

Hard links are useful when you need multiple names for the same file within the same partition, and symbolic links when you want to refer to files or directories in different locations or partitions.