Results 1 to 2 of 2

Thread: Is it possible to link our file to another file,

  1. #1
    Geek_Guest
    Guest

    Is it possible to link our file to another file,

    Question asked by visitor Vandana

    here my question is related to UNIX os.
    Is it possible to link our file to another file,if yes plz tell me how?
    and if the link is maintained then whether it possible if we change in one link then it is automatically reflected in to another link.plz tell me the command for this purpose with the help of an example.


  2. #2
    Contributing Member
    Join Date
    Feb 2007
    Answers
    47

    Re: Is it possible to link our file to another file,

    As if one name for a file weren't enough, sometimes we want to have two, three, or a dozen names for the same file. This operation of creating alternate names for a file is called linking. The two major forms of linking are hard links and symbolic links (also called symlinks or soft links).


    A hard link to a file is indistinguishable from the original name for the file; there's no particular link that is more the "real name" for the file than any other.

    The operating system keeps track of how many hard links reference the file at any particular time. When a file is first created, it starts with one link. Each new hard link increases the count. Each removed link reduces the count. When the last link to a file disappears, and the file is closed, the file goes away.

    Every hard link to a file must reside on the same mounted filesystem (usually a disk or a part of a disk). Because of this, you cannot make a new hard link to a file that is on a different mounted filesystem.


    A symbolic link is a special kind of a file that contains a pathname as data. When this file is opened, the operating system regards its contents as replacement characters for the pathname, causing the kernel to hunt through the directory tree some more, starting with the new name.




    A hard link protects the contents of a file from being lost (because it counts as one of the names of the file). A symlink cannot keep the contents from disappearing.

    The UNIX ln command creates hard links. The command

    ln file1 file2
    creates a hard link from the file file1 (which must exist) to file2.As with the mv command, the UNIX ln command performs some behind-the-scenes magic, allowing you to specify the target directory for the new alias without naming the file within the directory. The link function (like the rename function) is not so smart, and you must specify the full filename explicitly.

    To create a symbolic link from file1 to file2 (so that a reference to file2 is actually a reference to file1), you'd use something like this:

    ln -s file1 file2
    When you invoke ls -l on the directory containing a symbolic link, you get an indication of both the name of the symbolic link and where the link points.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact