所以我创建了一个符号链接:
ln -s /location/to/link linkname
Run Code Online (Sandbox Code Playgroud)
现在我想更改符号链接链接的位置.我怎么做?有没有办法做到这一点而不是先删除它?
mar*_*ton 40
您可以使用其他名称创建新链接,然后移动它以替换旧链接.
ln -s /location/to/link linkname
Run Code Online (Sandbox Code Playgroud)
后来
ln -s /location/to/link2 newlink
mv newlink linkname
Run Code Online (Sandbox Code Playgroud)
如果newlink
和linkname
在同一物理设备上,则mv
应该是原子的.
Phi*_*hil 26
试试ln -sf new_destination linkname
.
ben*_*all 17
如果符号链接目标是目录,则需要将该-T
标志添加到该mv
命令,否则它会将新符号链接移动到旧符号链接的目标目录中.
将网站自动切换到新版本的示例:
原始设置 - 网站存储在www1
目录中,vhost指向www
符号链接:
ln -s www1 www
Run Code Online (Sandbox Code Playgroud)
浏览网站,查看旧版本.
将新网站文件放在新www2
目录中.
为新网站设置新的符号链接:
ln -s www_new www2
Run Code Online (Sandbox Code Playgroud)
将www
符号链接移动到新网站的目录:
mv -T www_new www
Run Code Online (Sandbox Code Playgroud)
浏览网站,立即查看新版本.
在OSX上,ln的手册页说你可以这样做
ln -shf /location/to/link link name
Run Code Online (Sandbox Code Playgroud)
从手册页:
Run Code Online (Sandbox Code Playgroud)The options are as follows:
-F If the target file already exists and is a directory, then remove it so that the link may occur. The -F
option should be used with either -f or -i options. If none is specified, -f is implied. The -F option is
a no-op unless -s option is specified.
-h If the target_file or target_dir is a symbolic link, do not follow it. This is most useful with the -f
option, to replace a symlink which may point to a directory.
-f If the target file already exists, then unlink it so that the link may occur. (The -f option overrides any
previous -i options.)
-i Cause ln to write a prompt to standard error if the target file exists. If the response from the standard
input begins with the character `y' or `Y', then unlink the target file so that the link may occur. Other-
wise, do not attempt the link. (The -i option overrides any previous -f options.)
-n Same as -h, for compatibility with other ln implementations.
-s Create a symbolic link.
-v Cause ln to be verbose, showing files as they are processed.
Run Code Online (Sandbox Code Playgroud)
否.如果newpath已存在,symlink
系统调用将返回EEXIST
.您只能从文件系统中的新节点进行链接.这里有什么要求?如果由于unlink/symlink调用的非原子性而担心竞争,那么您可能需要重新考虑该体系结构以在其他地方提供同步.这种事情引入了一些可怕的安全漏洞.