LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Asking cp to copy preserving the whole source path. (https://www.linuxquestions.org/questions/linux-newbie-8/asking-cp-to-copy-preserving-the-whole-source-path-886161/)

stf92 06-13-2011 11:24 PM

Asking cp to copy preserving the whole source path.
 
cp (GNU coreutils 6.9).

Hi:
I have these files:
Code:

/usr/lib/seamonkey-1.1.2/defaults/profile/US/mimeTypes.rdf
/home/semoi/.mozilla/firefox/u88mwxdz.default/mimeTypes.rdf

I want to copy them to /xp/borrar/ such that the result is
Code:

/xp/borrar/usr/lib/seamonkey-1.1.2/defaults/profile/US/mimeTypes.rdf
/xp/borrar/home/semoi/.mozilla/firefox/u88mwxdz.default/mimeTypes.rdf

Can this be done with the cp command alone? If so, would you send me some guidelines? Thanks.

ssrameez 06-13-2011 11:33 PM

I am not sure cp alone can do this stuff.. But a simple solution in my mind..

mkdir -p /xp/borrar/usr/lib/seamonkey-1.1.2/defaults/profile/US
mkdir -p /xp/borrar/home/semoi/.mozilla/firefox/u88mwxdz.default/
cp -pr /usr/lib/seamonkey-1.1.2/defaults/profile/US/mimeTypes.rdf /xp/borrar/usr/lib/seamonkey-1.1.2/defaults/profile/US/
cp -pr /home/semoi/.mozilla/firefox/u88mwxdz.default/mimeTypes.rdf /xp/borrar/home/semoi/.mozilla/firefox/u88mwxdz.default/

Dont' whether it will suffice your need.

--Rameez

colucix 06-13-2011 11:37 PM

Try the --parents option of cp, that is designed exactly for the this behavior. In alternative you can always try rsync instead of cp.

stf92 06-13-2011 11:39 PM

Thanks for your reply. Yes, but you'll see: in fact, the number of files to copy is quite large and so, I'd need a more automated procedure. Regards.

Tinkster 06-13-2011 11:41 PM

Quote:

Originally Posted by stf92 (Post 4384772)
cp (GNU coreutils 6.9).

Hi:
I have these files:
Code:

/usr/lib/seamonkey-1.1.2/defaults/profile/US/mimeTypes.rdf
/home/semoi/.mozilla/firefox/u88mwxdz.default/mimeTypes.rdf

I want to copy them to /xp/borrar/ such that the result is
Code:

/xp/borrar/usr/lib/seamonkey-1.1.2/defaults/profile/US/mimeTypes.rdf
/xp/borrar/home/semoi/.mozilla/firefox/u88mwxdz.default/mimeTypes.rdf

Can this be done with the cp command alone? If so, would you send me some guidelines? Thanks.

Maybe cpio?
Code:

echo /home/semoi/.mozilla/firefox/u88mwxdz.default/mimeTypes.rdf | cpio -pamVd /xp/borrar
Untested.

[edit]Just saw responses posted between me clicking quote
and finishing my post; use find instead of echo to feed
many filenames if the dir tree is complex.[/edit]



Cheers,
Tink

stf92 06-14-2011 12:04 AM

colucix, either I made a very easy question or you provided a very clever answer.
Code:

bash-3.1$ mkdir pruebo
bash-3.1$ cp --parents /usr/lib/seamonkey-1.1.2/defaults/profile/US/mimeTypes.rdf pruebo
bash-3.1$ ls -R pruebo
pruebo:
usr

pruebo/usr:
lib

pruebo/usr/lib:
seamonkey-1.1.2

pruebo/usr/lib/seamonkey-1.1.2:
defaults

pruebo/usr/lib/seamonkey-1.1.2/defaults:
profile

pruebo/usr/lib/seamonkey-1.1.2/defaults/profile:
US

pruebo/usr/lib/seamonkey-1.1.2/defaults/profile/US:
mimeTypes.rdf
bash-3.1$

I had never before been presented with a case like this, of preserving the full name, if I remember well. Linux/Unix commands are great!

Tinkster 06-14-2011 02:24 AM

Quote:

Originally Posted by colucix (Post 4384783)
Try the --parents option of cp, that is designed exactly for the this behavior. In alternative you can always try rsync instead of cp.

Goes to show, once again, that reading the man pages of "old friends"
after an update makes perfect sense ;} ... thanks, colucix.


Cheers,
Tink

ssrameez 06-14-2011 02:25 AM

good one..
keep going.. :)


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