【问题标题】:copy the symbolic link in Solaris [closed]复制 Solaris 中的符号链接 [关闭]
【发布时间】:2010-10-16 15:33:51
【问题描述】:

我试图在 Solaris OS 上复制一个链接,但发现它并没有简单地复制链接,而是复制了链接指向的目录/文件的全部内容?这在 AIX、HP-UX、Linux 等其他操作系统中是没有的。

这是 Solaris OS 的正常行为吗?

【问题讨论】:

  • Solaris 符号链接是一场噩梦

标签: solaris symlink copying


【解决方案1】:

查理很接近,你想要-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”仍有问题。如果要复制的符号链接指向不存在的文件,cp 将不会复制它。
  • 是的,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
【解决方案2】:

我相信你想要cp -P(请查看手册页,因为我现在手头没有 solaris 框。)我隐约怀疑这是一个 System V 主义,但不会发誓。

【讨论】:

  • 没有这样的 -P 选项。我试过了,这是输出的样子: $ cp -P /opt/standard_perl/link /opt/standard_perl/link_new 用法:cp [-f] [-i] [-p] [-@] f1 f2 cp [-f] [-i] [-p] [-@] f1 ... fn d1 cp -r|-R [-H|-L| -P] [-f] [-i] [-p] [-@] d1 ... dn-1 dn
  • 是的,Solris 上有。请参阅docs.sun.com/app/docs/doc/816-5165/cp-1?l=en&a=view您确定您使用的是 Solaris?
【解决方案3】:

听起来您正在尝试复制单个符号链接。

您可能只想这样做:


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。

【讨论】:

    【解决方案4】:

    cpio 会为您解决问题吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-25
      • 1970-01-01
      • 1970-01-01
      • 2013-07-11
      • 2012-09-06
      • 2010-09-30
      相关资源
      最近更新 更多