Creating a soft link.

symbolic links are used in linux to create a link to a folder or a file which is located in a different location, so that the same file or folder can be accessed from both the locations.
Softlinks are created using the command

ln -s original_file link

Example:

If we have a file “temp1” in the path

/home/user1/folder1/temp1

And if we want to create a link to this file in the path

/home/user1/folder2/

We can do it as follows.

$ ln -s /home/user1/folder1/temp1 /home/user1/folder2/link

Now if we do a long listing of the new link that was created we can see that it is a soflink by the way it gets listed

$ ls -l /home/user1/folder2/link lrwxrwxrwx 1 user1 user1 5 Aug 18 15:45 link -> ../folder1/temp1

The first letter, l, in the long listing indicates that the file is a softlink and the last column indicates the file to which it is a softlink

The new link file is just a pointer to the original file and not a new copy of it and hence it occupies just enough space required for a link, which is very very small, rather than for the whole file.
The file can be opened and modified from either of the locations, and the changes will be reflected in files at both the locations.


Tags: ,
Copyright 2017. All rights reserved.

Posted August 18, 2012 by Tux Think in category "Linux