Copy symlink in Solaris

I try to copy the link to the Solaris OS, but I find that it does not just copy the link, but copies the entire contents of the directory / file to which the link refers. What is not in other operating systems, such as AIX, HP-UX, Linux.

Is this normal Solaris OS behavior?

+3
source share
4 answers

Charlie was close, you need flags -L, -Hor -Pwith a flag -R(maybe only -R -P). Similar flags exist for chmod(1)and chgrp(1). I 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
$ 

, 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.
+7

cp -P ( man-, .) , System V-ism, .

+1

cpio ?

0

, .

:


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, it can be very difficult to do without the GNU (or rsync) tools at all. Although there are solutions that often work, there is no solution that works on every β€œstandard” unix with any type of file name that you may encounter. If you intend to do this regularly, you must install GNU coreutils, find, cpio and tar, as well as rsync.

0
source

Source: https://habr.com/ru/post/1705664/


All Articles