exact purpose of links


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers exact purpose of links
# 1  
Old 08-18-2011
Bug exact purpose of links

please explain what is the exact purpose of hard link and soft link

which is best one

thanks in advance


regards,
surendra thota
# 2  
Old 08-18-2011
Consider you have a file called original , then you can create hardlink to this file using command given below
$ ln original hardlink

Now you can create a softlink to original file using command given below
$ ln -s original softlink

Now you can check using ln -li that both hardlink and original have same inode (147513106 ) but softlink has different inode
$ ls -il
147513106 -rw-rw-rw- 2 qa qa 10576 2011-08-18 15:54 hardlink
147513106 -rw-rw-rw- 2 qa qa 10576 2011-08-18 15:54 original.txt
147513105 lrwxrwxrwx 1 qa qa 12 2011-08-18 16:03 softlink -> original.txt

Soft link are special files that indicate OS a path where it can find the actual file.But hardlink is just different name to the same inode, inodes are unique for same partition.
If you delete softlink for eg rm softlink then the original file does not get deleted , but same is the case with hardlik i.e. if you delete hardlink then the original file does not gets deleted.

Advantages/Disadvantages:

a) Symbolick links have the advantage that they can point to files across file systems or across partitions. But hardlink can't link across partitions/file systems because inode is unique for each partition.

b) Hardlinks have the advantage that you can move the original file form its initial location to different location (say from myfolder/original.txt to differntfolder/original.txt) then the hard link will not get broken because it point to the original file using inode.But softlink will be broken if the original file will be moved from its initial location when softlink was created.For example if you created softlink to myfolder/original.txt then do 'ls -l' on softlink then you will see softlink->myfolder/original.txt now if you move original.txt to differntfolder/original.txt then the softlink will not work.

Last edited by newbielgn; 08-18-2011 at 10:10 AM..
This User Gave Thanks to newbielgn For This Post:
# 3  
Old 08-18-2011
Bug provide examples

in which situations these are useful

how the space is taken for these two types of links and how will be the inode structure for both

please provide me some examples

thanks

---------- Post updated at 07:49 PM ---------- Previous update was at 05:08 PM ----------

what is the idea behind having different names for the same data

may I have any real time example

thanks
# 4  
Old 08-18-2011
Quote:
Originally Posted by tsurendra
in which situations these are useful
It's a tool, not something with specific purposes in mind. It expands your options for organizing files and directories.

One of my users has a large website, larger than the amount of space I have in my /home/ partition, but still needs to login to /home/username. So I moved his home dir into /var/www/username and made /home/username a symlink to it.

Look in your /usr/lib/ directory and you'll find tons and tons of symlinks:
Code:
$ ls -l /usr/lib/libcurl*.so*
lrwxrwxrwx 1 root root     16 Nov  4  2010 /usr/lib/libcurl.so -> libcurl.so.4.2.0
lrwxrwxrwx 1 root root     16 Nov  4  2010 /usr/lib/libcurl.so.4 -> libcurl.so.4.2.0
-rwxr-xr-x 1 root root 302244 Nov  4  2010 /usr/lib/libcurl.so.4.2.0
$

Programs that really need version 4.2.0 of curl and no others can use the actual file, libcurl.so.4.2.0 and be assured that they're not going to use the wrong version by accident. Programs that're okay with any 4.x compatible version of curl load libcurl.so.4. And so forth.

It'd even be possible to install several different versions of the curl libraries, side by side, and pick which one you use by which one the symlinks point to. This is also useful for config files and binary programs -- Gentoo for instance lets me choose between several different versions of gcc, x, python, perl, and many other things by running a command to change symlinks to point at a different set of files.


I have a boot partition containing Linux kernels and such. It also contains a symlink named 'boot' that points to '.', i.e. the current directory. This seemed pretty useless, so I deleted it, and discovered that grub expects the files to be inside /boot/, not in /. Needed a rescue CD to fix that. Having a 'boot' symlink inside there lets me see files where I expect when the system's booted, /boot/filename, and still have them exist in /boot/filename when grub loads that partition all by itself. Without that symlink I'd end up needing to put them in silly places like /boot/boot/filename.

Hardlinks seem to be of more limited use since they can't cross filesystems. They're also more perplexing since there's no 'original' anywhere, nothing to tell you where the others are, but there's some things they can do which symlinks can't. Say you need access to a file inside a dir you don't have read-access to. If the sysadmin makes you a softlink for it, it still has to get into that dir and gives you access denied. If the sysadmin makes you a hardlink, though, you have direct access and don't need into someone else's dir -- it is literally the same file in more than one place.

This sameness is also useful for renaming files in use. Imagine you do this:

Code:
long-running-command > hugrfile

Whoops, you meant to name that hugefile. But you can't interrupt it in the middle and don't want to start over.
Code:
ln hugrfile hugefile
rm hugrfile

Once you've linked it, the same file exists in two places. Then delete the original, and it still exists in one place. None of these commands touch the data inside the file or interfere with any programs using them, it just alters the names available on the filesystem. Voila, file renamed during modification without a glitch.

Like files themselves, it's not so much what they're for, as what you want to do with them. They're general-purpose.

Last edited by Corona688; 08-18-2011 at 05:59 PM..
This User Gave Thanks to Corona688 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

echo exact xml tag from an exact file

Im stumped on this one. Id like to echo into a .txt file all names for an xml feed in a huge folder. Can that be done?? Id need to echo <name>This name</name> in client.xml files. $path="/mnt/windows/path" echo 'recording names' cd "$path" for names in $path than Im stuck on... (2 Replies)
Discussion started by: graphicsman
2 Replies

2. Shell Programming and Scripting

QUESTION1: grep only exact string. QUESTION2: find and replace only exact value with sed

QUESTION1: How do you grep only an exact string. I am using Solaris10 and do not have any GNU products installed. Contents of car.txt CAR1_KEY0 CAR1_KEY1 CAR2_KEY0 CAR2_KEY1 CAR1_KEY10 CURRENT COMMAND LINE: WHERE VARIABLE CAR_NUMBER=1 AND KEY_NUMBER=1 grep... (1 Reply)
Discussion started by: thibodc
1 Replies

3. UNIX for Dummies Questions & Answers

Purpose of <>

Hi, I have read from the book that , <> causes the file to be used as both input as well as output. Can anyone give me the scenario where <> will be useful? Thanks (10 Replies)
Discussion started by: pandeesh
10 Replies

4. AIX

List all the soft links and hard links

Hi I'm logged in as root in an aix box Which command will list all the soft links and hard links present in the server ? (2 Replies)
Discussion started by: newtoaixos
2 Replies

5. Solaris

Hard Links and Soft or Sym links

When loooking at files in a directory using ls, how can I tell if I have a hard link or soft link? (11 Replies)
Discussion started by: Harleyrci
11 Replies

6. UNIX for Advanced & Expert Users

Purpose of inv

Hi All Can anybody tell me what is the purpose of inv in the below command. ftp -inv $RFTPSERVER /temp/te.txt << EOF and << its stands for what.. Thanks (1 Reply)
Discussion started by: raju4u
1 Replies

7. UNIX for Dummies Questions & Answers

Purpose of /etc/cron.d

What is the purpose of /etc/cron.d? (3 Replies)
Discussion started by: proactiveaditya
3 Replies

8. Filesystems, Disks and Memory

Purpose of dsi log

Hi Please explain what is dsi log? Does it stores details related to File systems? (0 Replies)
Discussion started by: student2010
0 Replies
Login or Register to Ask a Question