请教个 ln -s 的问题

sh/bash/dash/ksh/zsh等Shell脚本
回复
blackthought
帖子: 57
注册时间: 2007-02-05 13:07

请教个 ln -s 的问题

#1

帖子 blackthought » 2015-08-05 17:07

代码: 全选

mkdir x
ln -s x y
ln -s x y
ln -s 了两次,为什么第二次执行时不提示文件存在,而是在x下面创建了一个软链接 x -> x
求解,谢谢
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 请教个 ln -s 的问题

#2

帖子 poloshiao » 2015-08-05 18:04

为什么第二次执行时不提示文件存在
1. http://manpages.ubuntu.com/manpages/viv ... /ln.1.html
By default, each destination (name of new link) should not already exist.

2. -f, --force
remove existing destination files
blackthought
帖子: 57
注册时间: 2007-02-05 13:07

Re: 请教个 ln -s 的问题

#3

帖子 blackthought » 2015-08-05 18:17

poloshiao 写了:
为什么第二次执行时不提示文件存在
1. http://manpages.ubuntu.com/manpages/viv ... /ln.1.html
By default, each destination (name of new link) should not already exist.

2. -f, --force
remove existing destination files

mkdir x
ln -s x y
ln -sf x y
加f还是那样
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 请教个 ln -s 的问题

#4

帖子 poloshiao » 2015-08-05 18:29

mkdir x
1. 表示 x 是 directory
ln -s x y
2. http://manpages.ubuntu.com/manpages/viv ... /ln.1.html
ln [OPTION]... -t DIRECTORY TARGET... (4th form)

3. 試試
sudo ln -s -t x y
sudo ln -s -f -t x y
blackthought
帖子: 57
注册时间: 2007-02-05 13:07

Re: 请教个 ln -s 的问题

#5

帖子 blackthought » 2015-08-05 18:43

poloshiao 写了:
mkdir x
1. 表示 x 是 directory
ln -s x y
2. http://manpages.ubuntu.com/manpages/viv ... /ln.1.html
ln [OPTION]... -t DIRECTORY TARGET... (4th form)

3. 試試
sudo ln -s -t x y
sudo ln -s -f -t x y
不行啊,第一次ln -s 就乱了,x y 应该是平级的
头像
susbarbatus
帖子: 2966
注册时间: 2010-04-10 16:14
系统: Arch Linux

Re: 请教个 ln -s 的问题

#6

帖子 susbarbatus » 2015-08-05 20:20

代码: 全选

ln -snf x y
x 是个目录,因此 y 是个指向目录的软链接,ln 默认的行为会 dereference 软链接,
因此第二次无论是 ln -s ... 还是 ln -sf ...,其效果都相当于 ln -s x x/,
目标是个目录的情况下,ln 的行为就是把链接建在目录下。

-n 可以取消 dereference 的行为:
-n, --no-dereference
treat LINK_NAME as a normal file if it is a symbolic link to a directory
沉迷将棋中……
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: 请教个 ln -s 的问题

#7

帖子 poloshiao » 2015-08-06 6:36

mkdir x
ln -s x y
1. http://manpages.ubuntu.com/manpages/viv ... /ln.1.html
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)

2. 先參考
ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
2-1. By default, each destination (name of new link) should not already exist.
2-2. 你的 TARGET 是指 x 還是 y ?
意思是 你的 LINK_NAME 是指 y 還是 x ?
blackthought
帖子: 57
注册时间: 2007-02-05 13:07

Re: 请教个 ln -s 的问题

#8

帖子 blackthought » 2015-08-06 9:45

susbarbatus 写了:

代码: 全选

ln -snf x y
x 是个目录,因此 y 是个指向目录的软链接,ln 默认的行为会 dereference 软链接,
因此第二次无论是 ln -s ... 还是 ln -sf ...,其效果都相当于 ln -s x x/,
目标是个目录的情况下,ln 的行为就是把链接建在目录下。

-n 可以取消 dereference 的行为:
-n, --no-dereference
treat LINK_NAME as a normal file if it is a symbolic link to a directory

:em38
回复