LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What are symbolic link good for? (https://www.linuxquestions.org/questions/linux-newbie-8/what-are-symbolic-link-good-for-4175471477/)

ulkoma 07-30-2013 12:22 PM

What are symbolic link good for?
 
Why do we need them? both types?

I familiar with creating them ..etc but why do we need them???

Regards

shivaa 07-30-2013 12:35 PM

In simple words, they are like shortcuts. Suppose you've some application installed somewhere and you everytime need to follow it's full path to launch it, so in order to avoid using full path, you create a symbolic link of it on your desktop for ease of access. Similarly, you create symlink to a file which is deep inside the directory tree, so you create a symlink in your home folder or on desktop to easily access it. Also, whatever changes you make in symlink original file, gets reflected in other one.

szboardstretcher 07-30-2013 12:39 PM

Seems the OP is asking why you need "Soft links" and "Hard links"

Which is explained in great detail on websites that can be found through Google.

https://www.google.com/search?q=hard+links+soft+links

Turned up 13,000 results if you'd like to research it further.

ulkoma 07-30-2013 12:45 PM

Quote:

Originally Posted by shivaa (Post 4999729)
In simple words, they are like shortcuts. Suppose you've some application installed somewhere and you everytime need to follow it's full path to launch it, so in order to avoid using full path, you create a symbolic link of it on your desktop for ease of access. Similarly, you create symlink to a file which is deep inside the directory tree, so you create a symlink in your home folder or on desktop to easily access it. Also, whatever changes you make in symlink original file, gets reflected in other one.

I forgot to add "apart from the obvious use of it in MSWindows" to my question

szboardstretcher 07-30-2013 12:59 PM

If you are familiar with creating them and ... etc then you know what they are for and why they are needed. And if you DO NOT know this, then you should research the subject on the internet. It is not difficult at all to find thousands of examples and howtos and documentation on the subject.

Doing the legwork yourself will ensure a much greater understanding.

Also:

http://www.linuxquestions.org/questi...ymlink-799528/
http://www.linuxquestions.org/questi...-links-531463/

Don't be afraid to search LQ before posting a question.

haertig 07-30-2013 01:00 PM

Assuming you know why you want links in the first place, and are only asking regarding the differences between hard links and symbolic links, for one, symbolic links can cross filesystems, hard links can't. Symbolic links can be created before the file they use as their target even exists. You can't create a hard link to a non-existant file. With a hard link, if you delete the original file, you can still access its contents via the hard link. With a symbolic link, once the original file has been deleted, you cannot access the original files contents anymore. I use symbolic links far more than hard links personally.

haertig 07-30-2013 01:06 PM

If you are indeed asking why you want links, any link type, in the first place, think of it this way:

If you want to show a friend in a different state what your house looks like, do you go up there and build a duplicate of your house (a "copy")? Or do you sent them a photograph of your existing house (a "link" - well not exactly, but for purposes of this discussion it's close enough). You don't want the resource usage (cost) of creating a duplicate "copy" of your house, you just want to "refer" to the existing house.

David the H. 08-02-2013 01:23 PM

Quote:

Originally Posted by haertig (Post 4999750)
With a hard link, if you delete the original file, you can still access its contents via the hard link.

Well, yes and no. Every regular file name you see on your system is actually a hard link. The name that you see on your file tree is really just a textual representation of an inode, a human-readable "link" to the actual location of the file on the disk.

So when you create a hard link to an existing file, you're actually, and literally, giving it another name, i.e. every single one of a file's hard links literally IS that file (which is why they all have to be on the same partition). If you remove one hard link, the file will still exist under its other hard links, if any. Only when you remove the last hard link do you actually delete the file (i.e. you unlink the inode completely and make that space available for new use).


A soft link, on the other hand, is a completely different beast. It's just a special kind of file that, when accessed, tells the system to jump to another location on the file tree and continue the processing there. Unlike hard links, they can cross partition boundaries, and the file location it's pointing to doesn't have to actually exist.

haertig 08-02-2013 02:03 PM

Quote:

Originally Posted by David the H. (Post 5001749)
Well, yes and no.

What you just said is exactly what I said. Or tried to say. Maybe I wasn't clear in the way I stated things.

David the H. 08-02-2013 04:13 PM

Don't sweat it. You basically had it right. But yeah, it could give the wrong impression, so I just thought I'd clarify it a bit more.

jpollard 08-02-2013 06:06 PM

One thing not mentioned is that hard links are only valid within a single filesystem. Softlinks/symbolic links have the path to the file, so that the link can point to a file not in the same filesystem as the link itself.

Another thing not mentioned (though this is true for both hard and soft links), is that it is possible to use the name of an executable as a parameter. This has been done for things requiring a root password -- the utility that asks for the password has a symbolic name pointing to it that identifies the function. After the utility gets a proper password, it then looks up the name it was invoked by in its table to identify the specific program to run.


All times are GMT -5. The time now is 03:49 PM.