相关疑难解决方法(0)

GNU cp 和 mv 中 -T 选项的附加值是什么?

为什么有些 GNU Coreutils 命令有-T/--no-target-directory选项?似乎它所做的一切都可以使用.传统 Unix 目录层次结构中的(自点)语义来实现。

考虑:

cp -rT /this/source dir
Run Code Online (Sandbox Code Playgroud)

-T选项可防止副本创建dir/source子目录。而是/this/source被标识dir并相应地在树之间映射内容。因此,例如/this/source/foo.c转到dir/foo.c等等,而不是到dir/source/foo.c

但这可以很容易地完成,而无需-T使用以下选项:

cp -r /this/source/. dir  # Probably worked fine since dawn of Unix?
Run Code Online (Sandbox Code Playgroud)

从语义上讲,尾随点组件被复制为 的子级dir,但当然该“子级”已经存在(因此不必创建)并且实际上是dir它本身,因此效果是用/this/path标识的dir

如果当前目录是目标,它工作正常:

cp -r /this/tree/node/. . # node's children go to current dir
Run Code Online (Sandbox Code Playgroud)

有什么东西你只能-T它来合理化它的存在吗?(除了对未实现点目录的操作系统的支持,文档中未提及的基本原理。)

上面的点技巧是否不能解决 GNU 信息文档中提到的相同竞争条件-T

cp coreutils

26
推荐指数
3
解决办法
2525
查看次数

标签 统计

coreutils ×1

cp ×1