Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.