ln 软件链接目录时,当链接文件已经存在时,结果非预期

创建软件链接的语法如下:

link -s  target  linkName

 

实例:

ln -s ssh_connect_home link1

 

但是当我们想把此链接指向第二个文件时,结果却不如意料那般:

 

仔细一看:

原来这个命令将软件链接创建到目录中去了,这是为何?

 

参考一下man:

SYNOPSIS

       ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)

       ln [OPTION]... TARGET                  (2nd form)

       ln [OPTION]... TARGET... DIRECTORY     (3rd form)

       ln [OPTION]... -t DIRECTORY TARGET...  (4th form)

 

DESCRIPTION

       In  the  1st  form, create a link to TARGET with the name LINK_NAME.  In the 2nd form, create a link to TARGET in the current directory.  In the 3rd and 4th forms, create links to each TARGET in

       DIRECTORY.  Create hard links by default, symbolic links with --symbolic.  By default, each destination (name of new link) should not already exist.  When creating hard links, each  TARGET  must

       exist.  Symbolic links can hold arbitrary text; if later resolved, a relative link is interpreted in relation to its parent directory.

 

原来,当链接文件已经存在时,被解析成了第三种格式,会在文件夹中创建到每个target的链接(链接名使用文件名)。

解决方法:

使用-n选项。

-n, --no-dereference

              treat LINK_NAME as a normal file if it is a symbolic link to a directory

 

 

 

 

如果target是文件,则并不存在这种问题:

 

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值