how to change a symbolic link instead of deleting it?
来源:互联网 发布:魅族手淘宝网的价格 编辑:程序博客网 时间:2024/05/01 08:49
someone told me that if i want to change a symbolic link after it is created, i should use the -f options,so i try:
andy@AndyMacBookPro:/usr/local/webdata$ ll unionlrwxr-xr-x 1 andy admin 10 3 30 15:34 union@ -> union_dev1andy@AndyMacBookPro:/usr/local/webdata$ ln -sfv union_branches unionunion/union_branches -> union_branchesandy@AndyMacBookPro:/usr/local/webdata$ ll unionlrwxr-xr-x 1 andy admin 10 3 30 15:34 union@ -> union_dev1andy@AndyMacBookPro:/usr/local/webdata$
but as you see , i can’t change the symbolic link at all, and i have another symbolic link under the /usr/local/webdata/union_dev1/ named union_branches.
so i decide to find the answer by myself, i find this article:
http://superuser.com/questions/749545/how-to-change-a-symbolic-link-to-a-directory-to-another-target
and someone use the :
ln -sfnv
to make it happen!great!
and the -n options means :
Use -n/–no-dereference (“treat LINK_NAME as a normal file if it is a symbolic link to a directory”):
这是我之前没有在意的,之前我只知道-f选项可以强制覆盖,但是linux这里的bug是如果发现目标是目录并且已经存在软链的话就会使用在此目录下创建软链而不是将此目录作为一个普通文件去处理,下面是更全面和专业的解释:
That is, ln -s target link will work like ln -s target link/target if link links to a directory.
Most Linux command tools will try to dereference symbolic links before applying their action, otherwise symbolic links would be mostly just confusing and almost useless. I guess the original ln authors thought consistency was more important than a certain amount of simplicity (with the risk of being confusing to people used to other tools) in this case.
其实也就是说,如果你的软链目标恰巧是一个文件而不是目录的话,ln -sf是可以的,但是如果不幸是一个目录,那么就会出现你意料之外的结果。
我在我的OSX系统man ln我本地的手册是这样的:
LN(1) BSD General Commands Manual LN(1)NAME link, ln -- make linksSYNOPSIS ln [-Ffhinsv] source_file [target_file] ln [-Ffhinsv] source_file ... target_dir link source_file target_fileDESCRIPTION The ln utility creates a new directory entry (linked file) which has the same modes as the original file. It is useful for maintaining multiple copies of a file in many places at once without using up storage for the ``copies''; instead, a link ``points'' to the original copy. There are two types of links; hard links and symbolic links. How a link ``points'' to a file is one of the differences between a hard and symbolic link. 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. Otherwise, do not attempt the link. (The -i option overrides any previous -f options.):
也可以参考这里的解释。
- how to change a symbolic link instead of deleting it?
- 如何创建软链接 how to create a symbolic link in clearcase
- How To Change the Background Color of a Tab Control
- How to change the color of a CEikLabel
- How to Change the Hostname of a Linux System
- how to change the default mode of a linux device
- How to Change the Hostname of a Linux System
- 发布应用到App Store问题:The CodeResources file is missing and it must be a symbolic link to _CodeSignature
- How would a model change if we minimized absolute error instead of squared error? What about the oth
- How to open UITextView web links in a UIWebView instead of Safari?
- Change filetype sl to renderman shader language instead of slang
- Mosquitoes as a Way to Fight Malaria Instead of Spreading It
- How to Deleting a Storage Repository From the Command Line?
- How to make a submit out of a <a href…>…</a> link?
- [LINUX LIVE USB]How to Make a bootable USB Drive to Install Fedora instead of using a physical DVD
- How to change text of CBA buttons?
- How to change text of CBA buttons?
- How to change text of CBA buttons?
- [线段树] hdu5195 DZY Loves Topological Sorting
- A problem displaying [localhost] caused Internet Explorer to refresh the webpage using Compatibility
- OpenCms9学习笔记(二)——OpenCms9下载安装
- 第四周 【项目2-分数类的雏形】
- 自定义实现Json字符串向C#对象的转变
- how to change a symbolic link instead of deleting it?
- 基于SSH2框架下的 用户注册 验证码功能
- 开源的PaaS方案:在OpenStack上部署CloudFoundry (四)使用Micro Bosh部署CloudFoundry
- Gson解析错误
- Roope的Cocos2d-x学习之旅 001:基础概念学习——导演、场景、层、精灵
- C++中main函数执行完毕后还可以执行其他语句么?
- Spring - href访问
- 第四周项目三 对象数组操作长方形类
- 【LeetCode】083.Remove Duplicates from Sorted List