cp -L vs. cp -H
With symlinks, tools have two things they can do:
- Treat the symlink as a symlink ("preserving its nature"), or
- Treat the symlink as the type of file that it points to.
Saying that -H
"preserves its nature" is not a contradiction. Consider the alternative. If you use -L
, any symlinks cp
finds will be opened, and their contents copied to the target file name. So the source was a symlink, but its copy is not a symlink. So it "lost its nature as a symlink".
Consider
$ 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
The difference in behavior between -L
and -H
comes when -r
is specified as well. cp
won't create symlinks in subdirectories with -L -r
but it will if you use -H -r
.