LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   copy both soft link and its linked file (https://www.linuxquestions.org/questions/programming-9/copy-both-soft-link-and-its-linked-file-289863/)

okeyla 02-13-2005 09:31 PM

copy both soft link and its linked file
 
As title , if i wanna do it by bash script , how to do that?
For example ,
I want to copy /usr/lib/libfreetype.so to somewhere.
But it is a soft link , linking to /usr/lib/libfreetype.6.3.2
What i desire is using a script to copy both of them to the destination and
keeping its linking relation.

===
P.S.
cp -L
cp -av
those two commands' parameter cannot satidfy me~

Best Regards,
Diego

foo_bar_foo 02-13-2005 09:53 PM

~/clean $ ls -l out
lrwxrwxrwx 1 user users 5 2005-02-13 22:42 out -> a.out

cp --no-dereference out ./test
cp a.out ./test

cd ./test
~/clean/test $ ls -l
-rwxr-xr-x 1 user users 8334 2005-02-13 22:47 a.out
lrwxrwxrwx 1 user users 5 2005-02-13 22:47 out -> a.out

if it gets more complex with long paths that need changing then just rm the link copy te file
and rebuild the link with ln -s

okeyla 02-13-2005 11:15 PM

Quote:

Originally posted by foo_bar_foo
~/clean $ ls -l out
lrwxrwxrwx 1 user users 5 2005-02-13 22:42 out -> a.out

cp --no-dereference out ./test
cp a.out ./test

cd ./test
~/clean/test $ ls -l
-rwxr-xr-x 1 user users 8334 2005-02-13 22:47 a.out
lrwxrwxrwx 1 user users 5 2005-02-13 22:47 out -> a.out

if it gets more complex with long paths that need changing then just rm the link copy te file
and rebuild the link with ln -s

Thanks for sharing your idea.
But the point is...how do i do it by script program?

Just take your code as example:
Code:

usage:super_cp file destination
in the script , we could know if file link to other or not.
copy it / them  to the destination.

(Moreover , I find sometimes there's soft link to anohter soft link file!)

okeyla 02-13-2005 11:30 PM

Quote:

Originally posted by foo_bar_foo
~/clean $ ls -l out
lrwxrwxrwx 1 user users 5 2005-02-13 22:42 out -> a.out

cp --no-dereference out ./test
cp a.out ./test

cd ./test
~/clean/test $ ls -l
-rwxr-xr-x 1 user users 8334 2005-02-13 22:47 a.out
lrwxrwxrwx 1 user users 5 2005-02-13 22:47 out -> a.out

if it gets more complex with long paths that need changing then just rm the link copy te file
and rebuild the link with ln -s

Thanks for sharing your idea.
But the point is...how do i do it by script program?

Just take your code as example:
Code:

usage:super_cp file destination
in the script , we could know if file link to other or not.
copy it / them  to the destination.

(Moreover , I find sometimes there's soft link to anohter soft link file!)


All times are GMT -5. The time now is 10:49 AM.