Unix Basics Part 15 | links | linking | soft link | hard link | symbolic link

Sdílet
Vložit
  • čas přidán 2. 06. 2024
  • Unix Basics | links | linking | soft link | hard link | symbolic link #unixtutorial
    Soft links/Symbolic Links/Hard links
    Links provide a mechanism to create a shortcut or different name for an existing file or directory, it may be helpful to have two different names that refer to the same file.
    ln - make links between files
    ln [options] [original filename] [link name]
    Types of links :
    Soft links/Symbolic Links
    Hard Links
    ---------------------------------------
    Soft links/Symbolic Links :
    A symbolic link is a special type of file that refers/points to another file or directory.
    You can access original file data using any of the created Symbolic link.
    Removing the symlink does not affect the original file.
    But If you delete the original file, then all the Symbolic links on this file will be broken and we can't access the data anymore.
    ln -s file_name/directory new_link_name
    ln -s test_soft_link.txt new_soft_link
    Check the inode no# using ls -li
    You need to on the same directory, where the link is present or give full path.
    unlink new_soft_link
    You can use rm command as well to remove the link, please note if you use rm command to delete the original file, then link will be broken.
    find directory -xtype l
    find directory -xtype l -delete
    --------------------------------------
    Hard Links :
    Each hard linked file is assigned the same Inode value as the original, therefore they reference the same physical file location.
    Links have actual file contents.
    If original file is removed, then the link will still show the content of the file.
    Hard link is a mirror copy of the original file. Deleting the original file will not impact anything, because the hard link file, will act as a mirror copy of the original file.
    Hard links are also shortcuts to files, but a hard link cannot be created for a folder or file available on a different file system. A hard link is basically a second filename for the same file.
    It makes efficient use of disc space by avoiding the unnecessary creation of record blocks.
    The speed of Hard Links is fast.
    You can't not hard link directories as compared to soft links.
    ln [original filename] [link name]
    ln file_name new_hard_link_name
    ls test_hard_link.txt new_hard_link
    unlink new_symlink
    Deleting the original file will not impact anything.
    #unixbasics #links #unix #unixtutorial #linking #unix #unixtutorial #softlink #hardlink #text #learning #coding #programming #symboliclink

Komentáře • 1