Symlinks … or how to be lazy.

We’ve been using the file /usr/share/dict/words in the past posts to look up words. We can use this to figure out if we’ve spelled things correctly, for example, looking for freind only to discover that it isn’t in the file. Oops, it’s spelled friend.

Every time we look up a word, we have to type /usr/share/dict/words. Over and over and… What we want is a shortcut to that file, so we don’t have to type the whole thing repeatedly. The shortcuts in Linux® are called symlinks, also known as symbolic links. The command to create them is ln and we create the symlnks as:

Alpha:~ computerlamp$ ln -s target destination

Where target is the file (or directory) we want to create a shortcut to and destination is our shortcut. So for example:

Alpha:~ computerlamp$ ln -s /usr/share/dict/words words

Will create a shortcut to /usr/share/dict/words as words in the current directory. You can more (or less) words, grep words, and generally treat it like any other file. If we want to remove it when we’re done or no longer need it, we can just use the command rm.

One other thing to note about it: If you use the command ls -F, you’ll see words@. The @at the end of the filename is your only sign that it’s a symlink. Otherwise, if you do just a plan ls, you’ll see words without any sign that it is a symlink. It’s just another file.

Back to creating the link. There’s no rule that says I had to link the file named words to a new file named words. I could have called it something else. Like:

Alpha:~ computerlamp$ ln -s /usr/share/dict/words heapbigwordlist

Or even:

Alpha:~ computerlamp$ ln -s /usr/share/dict/words thematrix

It’s nice how Linux® lets us be lazy.  I don’t want to type the entire path to the dictionary file out, I’ll just make a symlink.  And the symlink is a file, so I can treat it like one.

Leave a Reply

Your email address will not be published. Required fields are marked *