linux – cp -L与cp -H
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – cp -L与cp -H,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1860字,纯文字阅读大概需要3分钟。
内容图文
![linux – cp -L与cp -H](/upload/InfoBanner/zyjiaocheng/959/dd8713e314eb488abb36554d552af3d6.jpg)
问题
使用cp -H或cp -L复制文件时,我得到相同的结果:
$ls -l fileA
fileA -> fileB
$cp fileA somewhere/ -H
$ls -l somewhere/
fileA # fileA is a copy of fileB, only renamed, with same properties!
This answer here将两个选项描述为与-R组合使用的类似UNLESS.不适合我.软 – 硬链接文件成为它们在源指向的文件的重命名副本.
题:
cp -H和cp -L的正确用法是什么?这是预期的行为吗?
我试图解决:
man cp告诉我这两个选项完全一样,但是info cp的措辞让我更加困惑.也许有人可以帮我解决这个问题:
-H
If a command line argument specifies a symbolic link, then copy the file it points to rather than the symbolic link itself. However, copy (preserving its nature) any symbolic link that is encountered via recursive traversal.
这听起来像是一个矛盾:我想这是一个符号链接的本质«它指向某个地方……
-L, --dereference
Follow symbolic links when copying from them. With this option,cp
cannot create a symbolic link. For example, a symlink (to regular file) in the source tree will be copied to a regular file in the destination tree.
我知道符号链接不是常规文件,但是……我承认我在这里解释过这个解释.
解决方法:
使用符号链接,工具有两件事可以做:
>将符号链接视为符号链接(“保留其性质”),或
>将符号链接视为它指向的文件类型.
说–H“保留其性质”并不矛盾.考虑替代方案.如果使用-L,将打开任何符号链接cp查找,并将其内容复制到目标文件名.所以源代码是符号链接,但它的副本不是符号链接.所以它“失去了作为符号链接的本质”.
考虑
$mkdir subdir
$echo "some contents" > subdir/file
$ln -s file subdir/link
# definition of "list", the abbreviated ls -l output used below
$list() { ls -l "$@" | awk '$0 !~ /^total/ { printf "%s %s\t%s %s %s\n", $1, $5, $9, $10, $11 }' ; }
$list subdir
-rw-rw-r-- 14 file
lrwxrwxrwx 4 link -> file
$cp -rH subdir subdir-with-H
$list subdir-with-H
-rw-rw-r-- 14 file
lrwxrwxrwx 4 link -> file
$cp -rL subdir subdir-with-L
$list subdir-with-L
-rw-rw-r-- 14 file
-rw-rw-r-- 14 link
内容总结
以上是互联网集市为您收集整理的linux – cp -L与cp -H全部内容,希望文章能够帮你解决linux – cp -L与cp -H所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。