LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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

Reply
 
LinkBack Search this Thread
Old 03-15-2002, 02:34 PM   #1
Valerie
LQ Newbie
 
Registered: Jul 2001
Posts: 14

Rep: Reputation: 0
Symbolic links


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

Thanks!
Val
 
Old 03-15-2002, 02:44 PM   #2
Thymox
Senior Member
 
Registered: Apr 2001
Location: Cornwall, England.
Distribution: Debian + Ubuntu
Posts: 4,345

Rep: Reputation: 56
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?
 
Old 03-15-2002, 06:22 PM   #3
Aussie
Senior Member
 
Registered: Sep 2001
Location: Brisvegas, Antipodes
Distribution: Slackware
Posts: 4,590

Rep: Reputation: 56
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.
 
Old 03-15-2002, 08:34 PM   #4
linuxcool
LQ Addict
 
Registered: Jun 2001
Posts: 1,183

Rep: Reputation: 47
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 '.
 
Old 03-18-2002, 12:32 PM   #5
Valerie
LQ Newbie
 
Registered: Jul 2001
Posts: 14

Original Poster
Rep: Reputation: 0
Thanks, everyone! Your instructions were perfect and it worked like a charm.

Take care!
Valerie
 
Old 03-18-2002, 07:55 PM   #6
linuxcool
LQ Addict
 
Registered: Jun 2001
Posts: 1,183

Rep: Reputation: 47
You're welcome.
 
Old 03-19-2002, 10:22 AM   #7
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 30
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.
 
Old 03-20-2002, 05:27 AM   #8
Thymox
Senior Member
 
Registered: Apr 2001
Location: Cornwall, England.
Distribution: Debian + Ubuntu
Posts: 4,345

Rep: Reputation: 56
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?
 
Old 03-20-2002, 09:36 AM   #9
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 30
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.
 
Old 03-20-2002, 11:39 PM   #10
lithiumcloud
LQ Newbie
 
Registered: Mar 2002
Posts: 6

Rep: Reputation: 0
What is the use of hard links? as far as I can tell, symbolic links do everything hard links do and more.
 
Old 03-21-2002, 12:06 PM   #11
webtoe
Member
 
Registered: Apr 2001
Location: Cambridge, England
Distribution: Slackware 10, Fedora Core 3, Mac OS X
Posts: 617

Rep: Reputation: 30
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
 
Old 03-21-2002, 12:22 PM   #12
Sixpax
Member
 
Registered: Mar 2002
Distribution: Mandrake 8.1
Posts: 386

Rep: Reputation: 30
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.
 
Old 03-31-2002, 01:49 AM   #13
ryandelany
Member
 
Registered: Dec 2001
Location: Orange County, CA
Distribution: RedHat 7.2, 7.3, 8.0
Posts: 66

Rep: Reputation: 15
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
symbolic links durden2.0 Linux - Newbie 6 11-12-2008 03:06 AM
Symbolic Links petercool Linux - General 2 08-20-2003 11:15 AM
Symbolic links bkmesenbrink Linux - Newbie 2 11-13-2002 11:54 AM
Symbolic links pdstatha Programming 1 04-08-2002 09:50 PM
symbolic links winger Linux - General 5 04-06-2002 05:16 PM


All times are GMT -5. The time now is 12:09 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration