Symlinks in linux
The general concept of symlinks in linux is very similar to that of “shortcuts” in windows. After running the ln command, the source file is linked to the destination file. The “link” can be one of two types:
– Hard link : this can only be applied to single files. Whatever you do to one file is replicated to the other file. For example ln [original_file] [shortcut_file]
– Soft link : this can also be applied to directories. Whne accessing the source file, you are redirected to the destination file. For example ln -s [original_file] [shortcut file]. Notice the addition of the -s switch to indicate a soft link
In my particular case, I was researching symlinks because I wanted to redirect the contents of my /var/ftproot folder to my /extHD/ftproot. I added a larger external harddisk where I wanted to store my ftp documents. However I did not want to change all the config files that pointed towards /var/ftproot. So the idea was to create a symlink between the two directories.
Coming from a windows background, my initial reaction was to create a shortcut file (/var/ftproot) and point it towards my destination (/extHD/ftproot). This is not the right way of doing it. As per the above syntax, keep in mind:
ln -s [original_file] [shortcut_file]
Hence, in this case the command should be:
ln -s /extHD/ftproot /var/ftproot
since the /var/ftproot is the shortcut pointing towards /extHD/ftproot. One other note, make sure you dont already have a pre-existing folder called /var/ftproot, else I noticed a weird shortcut in the form of /var/ftproot/ftproot/ being created. Of course, the original folder (/extHD/ftproot) must be pre-existing.
Since I managed to mess the symlinks up, I came across the “error:Too many levels of symbolic links” when attempting to use the symlink. This basically means that the folders were pointing to each other. Due to a mistake I made, I ended up with /var/ftproot pointing towards /extHD/ftproot, which in turn pointed back towards /var/ftproot. Of course this sort of loop is not desirable, and has to be broken.
In order to see the symlinks and what folder points to what, you can use the
command. This gives output similar to: