Core Concepts: links

HardVsSymbolicLInks

This is one area of confusion for many new users to the shell (i.e. in terminal window).  Links are simply pointers, nothing more, nothing less.  Their job is pass along information on where to locate a particular file or folder (yes even folders can be linked).  Let’s overview each type:

Softlink

A softlink is merely a shortcut to another location or file.  This is what a typical user will create 99% of the time.  The basic syntax is as follows:

 ln -s /path/to/target/file.txt /link/path/mylink.txt

If you remove a softlink, it does not remove the original file.  Try to think of it as making a shortcut to a program launcher in windows.  If you remove the link, the original file stays in place, and life moves on.    Take special note, make a softlink is only truly useful for the GUI overlay of the system, i.e. the “file manager” application.  They bear no advantage, at least that I know of, in the terminal.  If you move a softlink, the softlink will be broken.  Perform a “ls -la” on the directory you placed your softlink, and you will notice that the file properties of it are prefixed with an l, and the file name itself having an appendage of “-> myfile.txt” where it is pointing to another file.  Very useful to remember.

Hardlink

A hardlink makes a special hard reference to a file by placing a marker directly in a hard disk location, rather some arbitrary file in any old place on you system (please reference the image above).  This hardlink is iron clad, so even if you move the hardlink, the link is not broken, unlike a softlink.  If you were to run “vim myfile.xt” and edit the contents, then return and perform “vim myfile_hardlink.txt” on the hardlinked file, the changes would still be there.  This is because the hardlink and the original “link” to the file on disk point to the same location.  In essence, the kernel does not care whether you created one link first or the other, they both point to the same location on disk.  This is due to the concept of inodes.  Consequently, if you delete a hardlink, it does not remove the original file.  Basic syntax is as follows:

ln /path/to/target/file.txt /link/path/mylink.txt

Now, if you for some reason, wish attempt to hardlink a directory, the syntax would be as follows:

ln -d /path/to/target/file.txt /link/path/mylink.txt

(note: will probably fail due to system restrictions, even for the superuser).   If it works, great, if it does not, most likely there is some restriction preventing you from doing so.  This occurs more on sensitive kernel areas and configuration folders. In summary What to take away from this simple.  Softlnks, or “symlinks,” represent the path to the file.  A hardlink represents where the file is on the actual hard disk. That’s it, any questions or comments, please leave them below. _professor

Advertisements

About professorkaos64

www.libregeek.org

Posted on 20130701, in Uncategorized and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s