Symlinking to Directories in Linux
Linux
If you need to symlink a directory in Linux, you need to make a distinction. The linked-to directory is intended to:
- Be the symlink: navigating to the symlink is equivalent to navigating to the linked directory
- Be accessed via a link within the linking directory
If you intend the former, you need to be careful that the directory does not already exist - if it does, the symlink will be placed inside the existing directory.
Example: The Directory is the Symlink
In this case, the ‘directory’ path/to/current
will contain the files from /path/to/target
. Crucially, /path/to/current
does not exist.
In this case, to access files in /path/to/target
via the symlink you would reference /path/to/current
:
Example: Directory Contains the Symlink
In this case, the /path/to/current
directory does exist:
In this case, to access files in /path/to/target
via the symlink you would reference /path/to/current/target
.
Rsync –link-dest
If you’re using the --link-dest
option with rsync
to make incremental backups, make sure you are referencing the correct symlinked reference directory - if not, rsync won’t create hardlinks and your backups will not be incremental. I recently made this error when mis-referencing the most recent backup by dynamically adding a symlink to an already existing directory.
Resources
comments powered by Disqus