默认情况下,cp测试其最后一个参数是否为现有目录。如果发生这种情况,请cp使用该源的基本名称在该目录内创建一个链接。也就是说,给定命令
cp foo/bar wibble
如果wibble是现有目录,则将cp源复制到wibble/bar。如果wibble不存在,则将cp源链接到wibble。
如果要确保副本始终为wibble,则可以指定--no-target-directory(alias -T)选项。这样,如果cp成功,则可以确保副本被调用wibble。如果wibble已经作为目录存在,cp则将失败。
以表格形式:
The target is …             Without -T               With -T
existing directory          copy in the directory    error
existing file (not dir)     overwrite                overwrite
does not exist              create                   create
唯一的区别是,-T如果目标是现有目录,则该命令将返回错误。当您期望目录不存在时,此功能很有用:您收到错误消息,而不是意外的事件。
mv和和相同ln。如果目标是使用的现有目录,-T它们会发出错误信号,而不是默默地执行其他操作。
使用cp,情况不同。如果您进行递归复制,并且源是目录,则将cp -T源的内容复制到目标中,而不是复制源本身。也就是说,给定
$ tree source destination 
source
└── foo
destination
└── bar
然后
$ cp -rv source destination
`source' -> `destination/source'
`source/foo' -> `destination/source/foo'
而
% cp -rvT source destination
`source/foo' -> `destination/foo'
               
              
--no-target-directory选项为我工作:只要使用--recursive,一切就可以[coreutils 8.12在GNU / Linux下使用]。主要区别在于,--no-target-directory使用内容而不是复制目录本身[研究仍在进行中]