LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-14-2011, 12:24 AM   #1
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Rep: Reputation: 51
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.

Last edited by stf92; 06-14-2011 at 12:34 AM.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 06-14-2011, 12:33 AM   #2
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
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
 
Old 06-14-2011, 12:37 AM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Try the --parents option of cp, that is designed exactly for the this behavior. In alternative you can always try rsync instead of cp.
 
2 members found this post helpful.
Old 06-14-2011, 12:39 AM   #4
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
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.
 
Old 06-14-2011, 12:41 AM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by stf92 View Post
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

Last edited by Tinkster; 06-14-2011 at 12:48 AM.
 
Old 06-14-2011, 01:04 AM   #6
stf92
Senior Member
 
Registered: Apr 2007
Location: Buenos Aires.
Distribution: Slackware
Posts: 3,485

Original Poster
Rep: Reputation: 51
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!

Last edited by stf92; 06-14-2011 at 01:12 AM.
 
Old 06-14-2011, 03:24 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,066
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
Quote:
Originally Posted by colucix View Post
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
 
Old 06-14-2011, 03:25 AM   #8
ssrameez
Member
 
Registered: Oct 2006
Location: bangalore
Distribution: Fedora, Ubuntu, Debian, Redhat
Posts: 82

Rep: Reputation: 6
good one..
keep going..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dow copy copy-protected cds with dd commant gh_D_ir Linux - Software 4 04-01-2011 05:41 PM
Can't access Windows. Weird, weird grub issue. MightyHard Linux - General 2 12-31-2008 05:35 PM
weird, weird problems with logitech precision USB gamepad ikataii Linux - Hardware 4 10-14-2005 05:31 AM
Weird, weird apache2 problem atheist Debian 1 09-17-2004 09:26 PM
boot error after using Copy Commander to copy debian system onto larger new drive Interceptor Linux - Hardware 7 05-04-2003 01:40 PM


All times are GMT -5. The time now is 11:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration