LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Symbolic links (https://www.linuxquestions.org/questions/linux-newbie-8/symbolic-links-16354/)

Valerie 03-15-2002 02:34 PM

Symbolic links
 
Can someone tell me what symbolic links are and how to create them? What are symbolic links are used for?

Thanks!
Val

Thymox 03-15-2002 02:44 PM

Symbolic links, or symlinks are created with the ln -s command. It's quite simple: ln -s originalfile symlinkname

They are pretty damn useful, in some circumstances. Take this, for example:

I have lots of Linux stuff on my Windows partition, which would be mounted as:
/mnt/win_e/To Be Burned To CD/Linux Stuff/
Now, some RPM programs (like the ol' Package Manager) seems not too happy about installing RPMs from a directory with spaces in it. So what do I do:
ln -s /mnt/win_e/To Be Burned To CD/Linux Stuff/ ~/stuff
Now, all I have to do is install the RPM files that appear to be under ~/stuff. Simple.

I think, though, for a more technical answe:
They create a file with the same inode as another, but with either a different name or in a different place.

Anyone care for a follow up?

Aussie 03-15-2002 06:22 PM

From "man ln",
Quote:

ln makes links between files. By default, it makes hard
links; with the -s option, it makes symbolic (or `soft')
links.
Hard links can only be make between files in the same directory while sym links can span directories.

linuxcool 03-15-2002 08:34 PM

Hard links have the same inode number.

Symbolic links are small files that contain information as to where the target file or directory is located. They have an inode number that is different then the file or directory they point to. Also, doing an ' ls -l ', will always give the permissions for a symbolic link as ' lrwxrwxrwx '.

Valerie 03-18-2002 12:32 PM

Thanks, everyone! Your instructions were perfect and it worked like a charm.

Take care!
Valerie

linuxcool 03-18-2002 07:55 PM

You're welcome. :)

Sixpax 03-19-2002 10:22 AM

Quote:

Hard links can only be make between files in the same directory while sym links can span directories.
Acutally that's incorrect. Hard links can only be made between files in the same partition.. they can be in different directories.

Thymox 03-20-2002 05:27 AM

So what about when you're using software RAID? Could you have hardlinks between files that appear to be on the same partition, but are actually on different disks?

Sixpax 03-20-2002 09:36 AM

Yes... hard links are a function of the filesystem, not the physical disk. Every file on a filesystem is assigned a unique inode number. When you create a hard link, the filesystem associates it with the same inode number as the origional file. It's kind of like making a copy of the file only the two never get out of sync. If either is deleted, the other stays intact.

lithiumcloud 03-20-2002 11:39 PM

What is the use of hard links? as far as I can tell, symbolic links do everything hard links do and more.

webtoe 03-21-2002 12:06 PM

hard links point to a particular file that will follow that file where ever it goes. it allows you to move the file that has been hardlinked and it will still work. it basically allows you to use several names for one file

its vaguely similar to a pointer in C where you can use it to give an alternate name to a variable

HTH

ALex

Sixpax 03-21-2002 12:22 PM

The only advantage to using hard links is if the origional file gets deleted accidently, you don't lose it, yet it doesn't take up any more space on the hard drive like a backup would. With a soft link, you're screwed if the file gets deleted. It's nice for making a mirror of files you want to be sure not to lose. Be aware though, that it's NOT a backup... it's just a pointer to the same spot on the disk as the origional file, so editing either will affect both.

ryandelany 03-31-2002 01:49 AM

One more advantage to using hard links is that you don't use up another inode. Believe or not you have a limited number of inodes. In theory if you made a bunch of symbolic links, you could use up all the inodes. This won't happen with hard links.

The main difference between the two is that a hard link won't work across filesystems and a soft link will.

Ryan


All times are GMT -5. The time now is 02:15 AM.