Fri 2 Nov 2007
Most people have some idea of how to create a file on their computer. Whether it be a Word document or a simple text file. However, most people have no idea how some of the cool things get done in the Unix and Linux operating systems and I hope to share one very small program called “ln” that allows you to do some really cool stuff.
First a few examples:
There are two types of links on Unix/Linux and we’ll get to both. The first is called a symbolic link and would normally be used to link a directory. For example: You have a folder that has gotten quite a bit larger than you expected and you need to move it. You have a lot of users or perhaps a website using the folder so moving it seems to be more complicated than you want to think about. Lets see the steps involved:
1) You find where you want to put the information.
2) You issue the command: mv currentfolder newfolder
Where currentfolder is where it is right now and new folder would be the full path to the new location.
3) You create a symbolic link to the new location back to the old location. Lets assume we’re in the folder where the original was before we moved it. issue the command: ln -s newfolder currentfolder
So in step 3 we created a symbolic link from the new location back to the original location. Now your site or systems are back on line and no one even knows you moved the data. So what’s with this hard link stuff? Well, hard linking is done with the “ln” command as well but without the -s on the end. What it’s used for are situations where you have a file that you want to share between multiple users but you don’t want to duplicate it by copying. You’d like them all to be able to make changes to it and when those changes are made you’d like for everyone to all see them.
To do this we’d create an original file on disk in some folder on the computer. Then we’d issue the command:
ln originalfile.txt newfile.txt
Where the originalfile.txt is the full path to the name of the file you wish to link to and newfile.txt is the full path to the new linked file you want to create. NOTE: Relative paths work as well here.
There are many cool things you can do with the link command and as an example Apple has released their latest Leopard OS to the world. One of the things it has is a very cool thing called Time Machine that not only backs up your data but provides a very cool interface for restoring things. In fact its so cool that the next time a friend comes over it will be the first thing you show them. Now when has that ever been the case? Hey Joey, take a look at my backup!
Anyway, the primary thing that allows Time Machine to do its job are hard linked files.
–glenn hancock