Operating System - HP-UX
1827296 Members
2012 Online
109960 Solutions
New Discussion

Re: Regarding copying links

 
SOLVED
Go to solution
Varun_5
Occasional Advisor

Regarding copying links

Hi,
when i am copying some link from one directory to another, i can see it is simply coying it, i mean to say suppose in one directory i have links like file -> ../../file then using command "cp -r" i am trying it to copy into some location and then when i am executing
" ls -l " at copied location it is simply showing file -> ../../file which has no meaning for copied location(IT IS NOT COPYING ACTUAL CONTENT)
I will be greatful to listen any reponse on this.

10 REPLIES 10
Chris Wilshaw
Honored Contributor
Solution

Re: Regarding copying links

The problem is with the way in which your original link is defined. cp is not able to evaluate the link in order to redefine it for your new location - it just copies it as it is.

You should really use the absolute path of the target file when creating a link.
Peter Godron
Honored Contributor

Re: Regarding copying links

Varun,
if the link has been created with a relative path i.e. ../../file , then copying the link will not change the pointer of the link. So the relative path will be maintained.
Same as creating a ln -s to a file and then moving that target file will not move your link pointer.
All I can suggest is recreating the link with absolute paths i.e. ///file
Regards
Varun_5
Occasional Advisor

Re: Regarding copying links

Thanks for so quick response, but we r working on porting project from solaris to hp , So we cant change the relative link to absolute link,
We are able to copy content of link on solaris using sme command " cp -R "
Is there any other option or way in which we can attain same behaviour on hp .
Seeking for ur immediate help ,
Thanks ,
varun
Gordon  Morrison
Trusted Contributor

Re: Regarding copying links

To copy a symbolic link to a new location, and still have a valid link that points to something, then one way or another, the absolute path must be specified when creating the link.
If the location of the target file changes depending on the platform , then you could try setting an environment variable with the absolute path of the application's home directory, and create the link using that. e.g.
in .profile:
export APPDIR=/path/to/application

Then create the link with:
ln -s ${APPDIR}/bin/application_exe ./application_exe

You could then copy that symbolic link to anywhere on that machine, and it would still point to the relevant file. You could use the same variable (with a different path) and the same ln command to create a similar link on another platform, and it would work there, but the symbolic links could not be copied between platforms.
What does this button do?
MarkSyder
Honored Contributor

Re: Regarding copying links

Assuming you still want a symbolic link you need to use the force option:

ln -fs file /full_path/file

Mark Syder (like the drink but spelt different)
The triumph of evil requires only that good men do nothing
Varun_5
Occasional Advisor

Re: Regarding copying links

Hi Mark,
Actually i dont have to create link..
i have to copy those files beacuse i have to give write permission for those file later on.
Can you suggest something else.
TwoProc
Honored Contributor

Re: Regarding copying links

Varun,

instead of using "cp" use rcp across the servers - this will always copy content instead of the actual link itself. The reason I know this is b/c I am always *wanting* the link and not what the link is pointing to. Basically, the opposite problem you have. So, I have to use tar instead rcp.

Anyways, set up remote shell across the two servers so that they work using .rhosts files.

To get the files onto HP server from the Sun Server... (logged onto the HP server).

rcp -rp sunbox:/disk1/stuff_i_want/ /disk1/stuff_i_want/

This should deliver to you all of your files sans symbolic links (with actual files instead).

HTH
We are the people our parents warned us about --Jimmy Buffett
Suraj_2
Valued Contributor

Re: Regarding copying links

Hi Varun

U can use tar for the same.

1) tar -cvf
2)copy the tar file to the other sun server
3)extract the same
tar -xvf

Hope this helps

Rgds
suraj
Varun_5
Occasional Advisor

Re: Regarding copying links

Hi Suraj,
That i am doing , Actually for that tarcvf will not solve our purpose but "tar -cvhf" will do that, but i was actually interested in knowing any option available with cp.
Thanks for your suggestion.
Rory R Hammond
Trusted Contributor

Re: Regarding copying links

I was able to accomplish this via the following on a HPUX machine using find and cpio:



find . -follow -depth -print |cpio -pdmh /usr/tmpi/tmp1

The above copies the data in the current directory (that contains symbolic links) to new temporary location populating it with the source files files (no links)

To transfer a directory tree to another system:
find . -follow -depth -print |cpio -oh > /tmp/file.out

then transfer file.out to the new location
from the destination directory use
cpio -idm < file.out


Your plan seems reasonable. You might have some problems, If your source directory tree has several symbolic links to the same source file. Transfering your data to the new system might cause data syncronation problems. Where a future file change updates one and not the other. Symbolic links solve this problem. My advice is do "find . -type l -print" , to see if you have some several links pointing to the same data. If you do, after the move, it should be simple enough to true up the few files you might find.

Good Luck
Rory
There are a 100 ways to do things and 97 of them are right