views:

2057

answers:

4

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.

Is this a normal behaviour of Solaris OS?

A: 

Will cipo do the trick for you?

NoahD
+1  A: 

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.

Charlie Martin
Well there is no such -P option.I tried and this is how the output looks:$ cp -P /opt/standard_perl/link /opt/standard_perl/link_newUsage: 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
kadeshpa
Charlie Martin
+4  A: 

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.
Martin Carpenter
Solaris can be infuriating.
ojblass
There is still a problem with 'cp -rP'. If a symbolic link to be copied points to non-existing file, cp will not copy it.
shura
A: 

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.

chuck