Friday, July 31, 2009

Creating a symlink in Ubuntu

Linking to a directory is a great way to access files and even trick programs to access files that are placed in a totally different place than it expects. What one is doing is creating a link which will list the content of a different directory when accessed.

So if I want a folder in my home area to point the my external harddrive mount point I could create a symbolic link, a symlink, to the external harddrive and its content would be shown when I accessed my symlink as a directory. The original location would also still be available.

To create a symlink one uses the program ln. In a console window, navigate to the directory where you want to create a symlink directory and type the following:
ln -s 'location to link to' 'name of symlink'

For example:
ln -s /media/ExternDrive moreFilesLink

Solution found at http://www.linuxforums.org/forum/linux-newbie/65415-creating-symlink.html

Update: To update/change where a symlink is pointing, use the flags sfn instead of just s:
ln -sfn 'location to link to' 'name of symlink'

For example:
ln -sfn /media/ExternDrive2 moreFilesLink

Solution: http://www.programmersparadox.com/2010/10/09/updating-a-symlink/

1 comment: