【发布时间】:2010-10-16 15:33:51
【问题描述】:
我试图在 Solaris OS 上复制一个链接,但发现它并没有简单地复制链接,而是复制了链接指向的目录/文件的全部内容?这在 AIX、HP-UX、Linux 等其他操作系统中是没有的。
这是 Solaris OS 的正常行为吗?
【问题讨论】:
-
Solaris 符号链接是一场噩梦
我试图在 Solaris OS 上复制一个链接,但发现它并没有简单地复制链接,而是复制了链接指向的目录/文件的全部内容?这在 AIX、HP-UX、Linux 等其他操作系统中是没有的。
这是 Solaris OS 的正常行为吗?
【问题讨论】:
查理很接近,你想要-L、-H 或-P 标志和-R 标志(可能只是-R -P)。 chmod(1) 和 chgrp(1) 存在类似的标志。我从下面的手册页中粘贴了一段摘录。
例子:
$ 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.
【讨论】:
cp -RP 在 Oracle Solaris 10 1/13 s10s_u11wos_24a SPARC 上为我工作:# cp -RP c2t240048FD8E70ED10d10s0 c4t0d0s0; # ls -l c4t0d0s0 lrwxrwxrwx 1 root root 91 Nov 15 22:39 c4t0d0s0 -> ../../devices/pci@0/pci@0/pci@8/pci@0/pci@9/SUNW,qlc@0/fp@0,0/ssd@w240048fd8e70ed10,a:a,raw
我相信你想要cp -P(请查看手册页,因为我现在手头没有 solaris 框。)我隐约怀疑这是一个 System V 主义,但不会发誓。
【讨论】:
听起来您正在尝试复制单个符号链接。
您可能只想这样做:
link_destination=`/bin/ls -l /opt/standard_perl/link|awk '{print $10}'`
ln -s $link_destination /opt/standard_perl/link_new
如果您尝试复制目录层次结构,通常在没有 GNU 工具(或 rsync)的情况下很难做到这一点。虽然有一些解决方案通常有效,但没有一种解决方案适用于您可能遇到的每种文件名的每个“标准”unix。如果您要定期执行此操作,则应安装 GNU coreutils、find、cpio 和 tar,以及 rsync。
【讨论】:
cpio 会为您解决问题吗?
【讨论】: