$ touch x
$ ln -s x y
$ ls -l x y
-rw-r--r-- 1 mjc mjc 0 Mar 31 18:58 x
lrwxrwxrwx 1 mjc mjc 1 Mar 31 18:58 y -> x
$ cp -R -P y z
$ ls -l z
lrwxrwxrwx 1 mjc mjc 1 Mar 31 18:58 z -> x
$
或者,默认情况下,普通的旧 tar 会愉快地使用符号链接,甚至是 Solaris 附带的古老版本:(
tar -cf foo | ( cd bar && tar -xf - )
其中 foo 是符号链接或包含符号链接的目录)。
/usr/bin/cp -r | -R [-H | -L | -P] [-fip@] source_dir... target
...
-H Takes actions based on the type and contents of the
file referenced by any symbolic link specified as a
source_file operand.
If the source_file operand is a symbolic link, then cp
copies the file referenced by the symbolic link for
the source_file operand. All other symbolic links
encountered during traversal of a file hierarchy are
preserved.
-L Takes actions based on the type and contents of the
file referenced by any symbolic link specified as a
source_file operand or any symbolic links encountered
during traversal of a file hierarchy.
Copies files referenced by symbolic links. Symbolic
links encountered during traversal of a file hierarchy
are not preserved.
-P Takes actions on any symbolic link specified as a
source_file operand or any symbolic link encountered
during traversal of a file hierarchy.
Copies symbolic links. Symbolic links encountered dur-
ing traversal of a file hierarchy are preserved.
Charlie was close, you want the -L, -H or -P flags with the -R flag (probably just -R -P). Similar flags exist for chmod(1) and chgrp(1). I've pasted an excerpt from the man-page below.
Example:
$ touch x
$ ln -s x y
$ ls -l x y
-rw-r--r-- 1 mjc mjc 0 Mar 31 18:58 x
lrwxrwxrwx 1 mjc mjc 1 Mar 31 18:58 y -> x
$ cp -R -P y z
$ ls -l z
lrwxrwxrwx 1 mjc mjc 1 Mar 31 18:58 z -> x
$
Alternatively, plain old tar will happily work with symbolic links by default, even the venerable version that ships with Solaris:
tar -cf foo | ( cd bar && tar -xf - )
(where foo is a symlink or a directory containing symlinks).
/usr/bin/cp -r | -R [-H | -L | -P] [-fip@] source_dir... target
...
-H Takes actions based on the type and contents of the
file referenced by any symbolic link specified as a
source_file operand.
If the source_file operand is a symbolic link, then cp
copies the file referenced by the symbolic link for
the source_file operand. All other symbolic links
encountered during traversal of a file hierarchy are
preserved.
-L Takes actions based on the type and contents of the
file referenced by any symbolic link specified as a
source_file operand or any symbolic links encountered
during traversal of a file hierarchy.
Copies files referenced by symbolic links. Symbolic
links encountered during traversal of a file hierarchy
are not preserved.
-P Takes actions on any symbolic link specified as a
source_file operand or any symbolic link encountered
during traversal of a file hierarchy.
Copies symbolic links. Symbolic links encountered dur-
ing traversal of a file hierarchy are preserved.
You want cp -P I believe (check the man page, as I don't have a solaris box handy right now.) I faintly suspect that's a System V-ism, but wouldn't swear to it.
If you are trying to copy a directory hierarchy, this can be very difficult to do in general without the GNU tools (or rsync). While there are solutions that often work, there is no solution that works on every "standard" unix with every type of filename you might encounter. If you're going to be doing this regularly, you should install the GNU coreutils, find, cpio, and tar, and also rsync as well.
发布评论
评论(4)
Charlie 很接近,您需要
-L
、-H
或-P
标志以及-R
标志(可能只是-R -P
)。chmod(1)
和chgrp(1)
也存在类似的标志。 我粘贴了下面的手册页的摘录。示例:
或者,默认情况下,普通的旧 tar 会愉快地使用符号链接,甚至是 Solaris 附带的古老版本:(
其中 foo 是符号链接或包含符号链接的目录)。
Charlie was close, you want the
-L
,-H
or-P
flags with the-R
flag (probably just-R -P
). Similar flags exist forchmod(1)
andchgrp(1)
. I've pasted an excerpt from the man-page below.Example:
Alternatively, plain old tar will happily work with symbolic links by default, even the venerable version that ships with Solaris:
(where foo is a symlink or a directory containing symlinks).
你想要
cp -P
我相信(检查手册页,因为我现在手边没有Solaris盒子。)我隐约怀疑这是一个System V-ism,但不会发誓它。You want
cp -P
I believe (check the man page, as I don't have a solaris box handy right now.) I faintly suspect that's a System V-ism, but wouldn't swear to it.听起来您正在尝试复制单个符号链接。
您可能只想这样做:
如果您尝试复制目录层次结构,如果没有 GNU 工具(或 rsync),这通常很难做到。 虽然有一些解决方案通常有效,但没有一个解决方案适用于您可能遇到的每种文件名类型的每个“标准”unix。 如果您打算定期执行此操作,则应该安装 GNU coreutils、find、cpio 和 tar,以及 rsync。
It sounds like you're trying to duplicate a single symlink.
You might want to just do:
If you are trying to copy a directory hierarchy, this can be very difficult to do in general without the GNU tools (or rsync). While there are solutions that often work, there is no solution that works on every "standard" unix with every type of filename you might encounter. If you're going to be doing this regularly, you should install the GNU coreutils, find, cpio, and tar, and also rsync as well.
cpio 会为你解决这个问题吗?
Will cpio do the trick for you?