[转]linux ls cp等命令的-H/-L参数
-H Symbolic links on the command line are followed. This option is assumed if none of the -F, -d, or -l options are specified.
-L Follow all symbolic links to final target and list the file or directory the link references rather than the link itself. This option cancels the -P option.
——摘自ls的manual
参数-L比较清楚,就是对所有的symlinks都dereference
但如果单独使用-H,结果并没有任何变化
后来看到superuser上一篇回答,终于弄懂了-H的作用:
linux -cp -H vs cp -L(What is a command line symbolic link)
其中有句话,看到后恍然大悟:
Without the -R switch, the behavior of cp -H and cp -L is identical.
感觉manual里没讲清楚,-H其实应该搭配着-R用的,这就是-H和-L的不同:
With the -R switch, cp -H only dereferences symbolic links that occur in the cp command itself, while -L also dereferences symbolic links inside the recursively copied directories.
比如,在 cp -HR source/ dest/
中,如果 source/
是symlink,那cp就会把symlink指向的原文件copy到 dest/
,但是,对于 source/
中包含的symlinks,仅仅copy 这些symlinks本身
However, if cp encounters any symlinks in source’s subdirectories, it will create symlinks in the destination folder.
而 cp -HL source/ dest/
则不仅dereference command line中的source(symlink),还会对递归中遇到的所有symlinks进行dereference