[SOLVED] Copy subfolder to another directory preserving parent name | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

[SOLVED] Copy subfolder to another directory preserving parent name

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 09-16-2013
alex2005 alex2005 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 18 September 2014, 3:35 AM EDT
Posts: 30
Thanks: 16
Thanked 2 Times in 2 Posts
[SOLVED] Copy subfolder to another directory preserving parent name

Hi,

I have the following folder structure:


Code:
Folder6100/Data
Folder6100/Data
Folder6120/Data
Folder6120/Data
Folder6140/Data
Folder6140/Data
Folder6160/Data
Folder6160/Data
Folder6180/Data
Folder6180/Data
Folder6200/Data
Folder6220/Data
Folder6240/Data
Folder6260/Data
Folder6280/Data
Folder6300/Data
Folder6320/Data
Folder6340/Data
Folder6360/Data
Folder6380/Data
Folder6400/Data
Folder6420/Data
Folder6440/Data
Folder6460/Data
Folder6480/Data
Folder6500/Data

I would like to copy all files under
Code:
Folder61[6-8]*/Data Folder63[2-6]*/Data

to an external disk
Code:
"/media/My Disk"

.

Using the following command :

Code:
cp -rpv Folder61[6-8]*/Data Folder63[2-6]*/Data "/media/My Disk"

creates on the external disk the Data folder and copy all the files in this directory.

What command can I use in order to preserve the path?

Desired disk content is:


Code:
Folder6160/Data
Folder6180/Data
Folder6320/Data
Folder6340/Data
Folder6360/Data

I need to copy only Data folder since under FolderXXXX I have some files that don't need to be copied.

Thanks in advance.
Sponsored Links
    #2  
Old 09-16-2013
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 22 September 2014, 9:56 PM EDT
Location: Saskatchewan
Posts: 19,409
Thanks: 790
Thanked 3,273 Times in 3,068 Posts
Hmm.


Code:
tar -cf - Folder61[6-8]*/Data Folder63[2-6]*/Data | tar -C "/media/My Disk" -xf -

The Following User Says Thank You to Corona688 For This Useful Post:
alex2005 (09-16-2013)
Sponsored Links
    #3  
Old 09-16-2013
alex2005 alex2005 is offline
Registered User
 
Join Date: Nov 2010
Last Activity: 18 September 2014, 3:35 AM EDT
Posts: 30
Thanks: 16
Thanked 2 Times in 2 Posts
Thank you for your quick respond.

The command worked very well.
The Following User Says Thank You to alex2005 For This Useful Post:
Corona688 (09-16-2013)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Catching the xml tag when only parent directory is known ..not the actual directory punpun66 Shell Programming and Scripting 4 09-08-2013 12:33 PM
Copy real file from a shortcut preserving the time stamps and directory tree gogok_bg Shell Programming and Scripting 6 03-19-2013 11:39 AM
Link multiple files from different subfolder to a new subfolder total_ysf Shell Programming and Scripting 6 07-19-2011 04:13 AM
create tar archive without preserving directory structure? Special_K UNIX for Dummies Questions & Answers 2 03-18-2009 11:52 AM
How to read a subfolder one by one in parent folder? kamatchirajan Shell Programming and Scripting 1 01-08-2009 04:56 PM



All times are GMT -4. The time now is 06:20 AM.