I have update software in /opt/minergate-cli
. I've renamed the directory minergate-cli
to minergate-old
with an mv
command, then installed a newer version of the software giving the same directory name.
Assuming I had an old program and now a new program by the same name, that being "minergate" what happens to any symbolic links pointing to the program minergate?
Are they pointing to the original program living in minergate-old
, or did the link move to the new program minergate.cli
?
Summary
Symlinks do not follow the files to which they point. If you have
link_file -> original_file
and you domv original_file original_file.backup
thelink_file
will be brokenIf you recreate original filename ( which is what OP did ) the symlink will work again
If you have to make
link_file -> original_file.backup
, you have to deletelink_file
and create it again, pointing to new filenameAnswer
Once you move a file to which symlink points, symlink is broken aka dangling symlink. You have to delete it and create new one if you want to point to the new filename.
For example, let's create a symlink to file:
Now let's rename the file. You will see symlink still points to the pathname that no longer exists (which is important, file exists, pathname - does not):
If you can rename file to original pathname, the symlink will start working.
$ mv testfile.txt.bak testfile.txt $ cat mysymlink one two three
If renaming is not an option and you may not rename the file, create a new symlink and delete the old one.
If the symlink target
/opt/minergate-cli
has been re-created when new version of application was installed, the symlink will point to new file. If the new file has different filename, then symlink will be broken. Symlinks do not follow filename if filename was moved, as in OP's example when they didmv /opt/minergate-cli /opt/minergate.old
, so symlink will still keep pointing to/opt/minergate-cli
regardless if that file exists or not.See also
A symlink just holds the name of the file that it points to. (hint, do
ls -l symlink
and note its file size). If you delete the target file, but then create a new file with the same name, the symlink will happily keep working, referring to the new file contents:You may be think about a "hard" link, which refers to the target file's inode:
here
hardlink
is the same file as the originalfile
file.