unix Links

gudii9
gudii9 used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
You can see them as shortcuts in Windows

Commented:
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  

Commented:
2nd + :  they eliminate duplicate copies of the same program , though better solution is add the file (if executable )to  $PATH variable
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Top Expert 2007
Commented:
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

Commented:
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.


Commented:
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.
ozo
Most Valuable Expert 2014
Top Expert 2015
Commented:
grep, fgrep and egrep are often links to the same binary, which changes its behaviour depending on the name with which it was invoked.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial