Results 1 to 4 of 4

Thread: Softlink and Hardlink confirmation (cp, cp -l, ln, ln -s)

  1. #1
    Join Date
    Apr 2009
    Beans
    80
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Wink Softlink and Hardlink confirmation (cp, cp -l, ln, ln -s)

    Hi All,
    Can you please verify the following statements for me? so I can have better understanding in Linux / Ubuntu

    ln -s <source> <destination>,

    • Similar to shortcut in Windows
    • creating small 'link file' under different inode
    • if source file content changed, the destination also changed and vice versa
    • if source deleted / moved, it will lose the 'link' to the destination file
    • Also called by softlink / symbolic link

    ln <source> <destination>,

    • creating same file content under same inode
    • if source file content changed, the destination also changed and vice versa.
    • if source file deleted, it will not delete the destination
    • Also called by hardlink

    cp -l <source> <destination>
    • totally the same as ln command

    cp <source> <destination>

    • creating totally a different same file content under different inode
    • if source file changed, destination file will not changed
    • if source file deleted, destination file will not changed / deleted

    Thanks heaps
    Last edited by televisi; August 28th, 2009 at 09:07 AM.

  2. #2
    Join Date
    Nov 2006
    Location
    India
    Beans
    1,246
    Distro
    Ubuntu Development Release

    Re: Softlink and Hardlink confirmation (cp, cp -l, ln, ln -s)

    Quote Originally Posted by televisi View Post
    Hi All,
    Can you please verify the following statements for me? so I can have better understanding in Linux / Ubuntu

    ln -s <source> <destination>,

    • Similar to shortcut in Windows
    • creating small 'link file' under different inode
    • if source file content changed, the destination also changed and vice versa
    • if source deleted / moved, it will lose the 'link' to the destination file
    • Also called by softlink / symbolic link

    ln <source> <destination>,

    • creating same file content under same inode
    • if source file content changed, the destination also changed and vice versa.

    • if source file deleted, it will not delete the destination
    • Also called by hardlink

    cp -l <source> <destination>
    • totally the same as ln command

    cp <source> <destination>

    • creating totally a different same file content under different inode
    • if source file changed, destination file will not changed
    • if source file deleted, destination file will not changed / deleted

    Thanks heaps
    Maybe this will explain better.

    http://ubuntuforums.org/archive/index.php/t-287447.html

    A hard disk is like two names for the same file.If you change one,the other one also changes.Because even though you are seeing 2 files ,they really are the same file.You could even move their locations and edit one to see same changes in the other.

    The rest of the stuff is correct i suppose.
    But iam not sure about the cp -l, i think its same as ln -s, that means a soft link.
    Last edited by rajeev1204; August 28th, 2009 at 08:31 PM.

  3. #3
    Join Date
    Apr 2009
    Beans
    80
    Distro
    Ubuntu 9.04 Jaunty Jackalope

    Re: Softlink and Hardlink confirmation (cp, cp -l, ln, ln -s)

    Is that correct that hardlinks cannot be created under 2 different partitions / drives / disks?

  4. #4
    Join Date
    Dec 2008
    Location
    USA
    Beans
    89

    Re: Softlink and Hardlink confirmation (cp, cp -l, ln, ln -s)

    Is that correct that hardlinks cannot be created under 2 different partitions / drives / disks?
    Yes.
    A hardlink does not create a duplicate file; it creates another reference to the same inode.

    More detailed explanation: In Windows filesystems the basic reference is the filename. Each file has different one - and only one.

    However, in Unix filesystems the basic reference is the inode. This has one(or more) filenames "linked" to it. When you run ln without the -s option, it creates another filename "linked" to the same inode. Since it is merely another link to the same inode, it cannot span different partitions.


    Symbolic links can, since they are usually nothing more than a string pointing to the destination file name that are treated as a special case by the OS.
    Last edited by gsocker; August 30th, 2009 at 03:42 AM. Reason: Better explanation

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •