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..
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:
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:
Whoops, you meant to name that hugefile. But you can't interrupt it in the middle and don't want to start over.
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..
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)
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)
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)
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)