About Linux FAQ

Browse More FAQs:

Unix Create a Symbolic Link

Posted by Vivek Gite [Last updated: May 15, 2008]

Q. How do I create links under UNIX / Linux operating systems?

A. You need to use ln command, which is a standard Unix / Linux / BSD command, used to create links to files. There are two types of links under UNIX, hard and soft link:

Hard link vs. Soft link in Linux or UNIX

[a] Hard links cannot links directories ( cannot link /tmp with /home/you/tmp)
[b] Hard links cannot cross file system boundaries ( cannot link /tmp mounted on/tmp to 2nd hard disk mounted on /harddisk2)
[c] Symbolic links refer to a symbolic path indicating the abstract location of another file
[d] Hard links, refer to the specific location of physical data.

UNIX Create Symboliclink Command

To create a symbolic link, enter
$ ln -s {/path/to/file-name} {link-name}
$ ln -s /shared/sales/data/file.txt sales.data.txt
$ vi sales.data.txt
$ ls -l sales.data.txt

To delete a link, enter
$ rm {link-name}
$ rm sales.data.txt
$ ls -l
$ ls -l /shared/sales/data/file.txt

If you delete the soft link itself (sales.data.txt) , the data file would still be there ( /shared/sales/data/file.txt ). However, if you delete /shared/sales/data/file.txt, sales.data.txt becomes a broken link and data is lost.

UNIX Create Hardlink Command

To create hard link, enter (without the -s option):
$ ln {file.txt} {hard-link}
$ ln /tmp/file link-here

You can delete hard link with rm command itself:
$ rm {hard-link}
$ rm link-here

If you delete a hard link, your data would be there. If you delete /tmp/file your data still be accessible via link-here hard link file.

See how to create a hard links in Linux / UNIX for more information.

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Other Helpful FAQs:

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , , , , , , , , , ,

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.