I am trying to copy a link on Solaris OS but find that it does not simply copy the link instead copies the whole contents of the directory/file the link is poinitng to? Which is not in other OSes like AIX,HP-UX,Linux.
我试图在Solaris OS上复制一个链接,但发现它不是简单地复制链接而是复制链接指向的目录/文件的全部内容?其他操作系统不支持AIX,HP-UX,Linux等。
Is this a normal behaviour of Solaris OS?
这是Solaris OS的正常行为吗?
4 个解决方案
#1
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.
查理很接近,你想要带-R标志的-L,-H或-P标志(可能只是-R -P)。 chmod(1)和chgrp(1)存在类似的标志。我在下面的手册页上贴了一段摘录。
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会默认使用符号链接,甚至是Solaris附带的古老版本:
tar -cf foo | ( cd bar && tar -xf - )
(where foo is a symlink or a directory containing symlinks).
(其中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.
#2
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.
你想要cp -P我相信(查看手册页,因为我现在没有方便的solaris盒。)我隐约怀疑这是一个System V-ism,但不会发誓。
#3
It sounds like you're trying to duplicate a single symlink.
听起来你正试图复制一个符号链接。
You might want to just do:
您可能只想这样做:
link_destination=`/bin/ls -l /opt/standard_perl/link|awk '{print $10}'`
ln -s $link_destination /opt/standard_perl/link_new
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.
如果您尝试复制目录层次结构,如果没有GNU工具(或rsync),这通常很难做到。虽然有些解决方案通常可以使用,但是没有解决方案适用于您可能遇到的每种类型文件名的每个“标准”unix。如果您要定期执行此操作,则应安装GNU coreutils,find,cpio和tar,以及rsync。
#4
Will cpio do the trick for you?
cpio会为你做的伎俩吗?
#1
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.
查理很接近,你想要带-R标志的-L,-H或-P标志(可能只是-R -P)。 chmod(1)和chgrp(1)存在类似的标志。我在下面的手册页上贴了一段摘录。
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会默认使用符号链接,甚至是Solaris附带的古老版本:
tar -cf foo | ( cd bar && tar -xf - )
(where foo is a symlink or a directory containing symlinks).
(其中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.
#2
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.
你想要cp -P我相信(查看手册页,因为我现在没有方便的solaris盒。)我隐约怀疑这是一个System V-ism,但不会发誓。
#3
It sounds like you're trying to duplicate a single symlink.
听起来你正试图复制一个符号链接。
You might want to just do:
您可能只想这样做:
link_destination=`/bin/ls -l /opt/standard_perl/link|awk '{print $10}'`
ln -s $link_destination /opt/standard_perl/link_new
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.
如果您尝试复制目录层次结构,如果没有GNU工具(或rsync),这通常很难做到。虽然有些解决方案通常可以使用,但是没有解决方案适用于您可能遇到的每种类型文件名的每个“标准”unix。如果您要定期执行此操作,则应安装GNU coreutils,find,cpio和tar,以及rsync。
#4
Will cpio do the trick for you?
cpio会为你做的伎俩吗?