unix Links

I was not clear about unix 'Links' concept. How same file has different name in different directory. It seems confusing to me. I wonder what are the practical uses, advantages, disadvantages, applications of links. What other operating system has similar concept? Please advise.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can see them as shortcuts in Windows

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Advantages are numerous but first You need to diff. between softlinks which are exactly like shortcuts and hardlinks that basically pointers to the real file and will behave the same way the file'd be .First great advantage of all links - they save space on Your HDD  
2nd + :  they eliminate duplicate copies of the same program , though better solution is add the file (if executable )to  $PATH variable
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

There are two types of links: hardlink and softlink

Hardlink is simply another name for the same file (not a copy). The advantages are:

- You can have links to the same file with different names
- You can have links for the same file from different directories
- You can safe files from accidental delete
- Some programs run differently when called by different name (e.g. vi and ed)

hard links will work within the same file system only and cannot work across file systems
hard links cannot be used for directories

The softlinks will work across file systems and can point to a directory

soft links will not protect you against original file deletion and will not work if the original file name is changed

To make links between files you need to use ln command. A symbolic link (also known as a soft link or symlink) consists of a special type of file that serves as a reference to another file or directory. Unix/Linux like operating systems often uses symbolic links.

Two types of Links:
1)symbolic links: Refer to a symbolic path indicating the abstract location of another file
2)hard links : Refer to the specific location of physical data.

To create a symbolic link in Unix or Linux, at the shell prompt, enter the following command:
ln -s {target-filename} {symbolic-filename}

A hard link to a file is indistinguishable from the original directory entry; any changes to a file are effectively independent of the name used to reference the file. Hard links may not normally refer to directories and may not span file systems.

ln {source} {link}
(source:- is an existing file.
link :- is the file to create (a hard link)).

Hard Links Limitations:-
There are some issues with hard links that can sometimes make them unsuitable. First of all, because the link is identical to the thing it points to, it becomes difficult to give a command such as "list all the contents of this directory recursively but ignore any links". Most modern operating systems don't allow hard links on directories to prevent endless recursion. Another drawback of hard links is that they have to be located within the same file system, and most large systems today consist of multiple file systems.

One common scenario where symbolic or softlinks are used is version control. For example, you can have a symbolic link called latest, working to the latest or working version of the file.

This way you can easily change versions by changing its link.
grep, fgrep and egrep are often links to the same binary, which changes its behaviour depending on the name with which it was invoked.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.