I was reading through some source code recently that updated the code on a server. Instead of just writing this to update myfile:
mv myfile.inactive myfile
There was this:
rm myfile
ln -s myfile.inactive myfile
What is the difference? Why would you want to do it the second way?
myfile may be an executable, or a currently running process, if that makes a difference.
the first version rename the
myfile.inactiveintomyfile. After that command there is nomyfile.inactiveanymorethe second creates an symlink to the
myfile.inactive. So this file is still there. When you remove (rm myfile) the file you only remove the symlink. Keep in mind, if you change the myfile it is also changed in myfile.inactive.This version is good to change easily the version you are using. e.g. myfile.debug, myfile.live, myfile.version1, myfile.version2 … you only need to change the symlink to one of the files to “activate” the one you want.