删除文件和符号链接与覆盖文件
我最近正在阅读一些源代码,更新了服务器上的代码。而不是仅仅写这个来更新myfile
:
mv myfile.inactive myfile
有这样的:
rm myfile
ln -s myfile.inactive myfile
有什么区别?为什么你想用第二种方式来做呢?
myfile
可能是一个可执行文件,也可能是一个当前正在运行的进程(如果有区别的话)。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个版本将
myfile.inactive
重命名为myfile
。在该命令之后,不再有myfile.inactive
了,第二个命令创建了一个指向
myfile.inactive
的符号链接。所以这个文件仍然存在。当您删除 (rm myfile
) 文件时,您仅删除了符号链接。请记住,如果您更改 myfile,它也会在 myfile.inactive 中更改。这个版本很好,可以轻松更改您正在使用的版本。例如 myfile.debug、myfile.live、myfile.version1、myfile.version2 ...您只需更改其中一个文件的符号链接即可“激活”您想要的文件。
the first version rename the
myfile.inactive
intomyfile
. After that command there is nomyfile.inactive
anymorethe 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.