LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-26-2012, 10:23 AM   #1
Drigo
Member
 
Registered: Jun 2009
Posts: 111

Rep: Reputation: 17
Unhappy Copy or scp specific files in sub directories maintaining same tree structure...???


Let say I have 3 subdirectories with:

MainDir:
DirA:
xyz.txt
abc.avi
def.mp3
hij.txt

DirB:
xyz.txt
abc.avi
def.mp3
hij.txt


DirC:
xyz.txt
abc.avi
def.mp3
hij.txt


How can I copy a single file within subdirectories to get a directory tree like:

main_Directory
DirA:
xyz.txt
DirB:
xyz.txt
DirC:
xyz.txt


I need something like.. cp -r <Some options> mainDir*/*/xyz* to <NewLocation>

What about in scp???
 
Old 09-26-2012, 10:50 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 8,500

Rep: Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431Reputation: 2431
have you tried tar?
tar cf - <files you want to copy> | tar -C <target dir> xf -
(not tested)
 
Old 09-26-2012, 11:22 AM   #3
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
"rsync -R" would do it.
 
Old 09-26-2012, 12:09 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,332
Blog Entries: 55

Rep: Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533Reputation: 3533
...as could 'cd /newlocation; find /oldlocation --whatever-specs | cpio -pdmu .;'. (One of the differences, if you would be interested in that sort of stuff, is that tar can preserve both extended attributes and SELinux contexts, rsync can preserve extended attributes and cpio doesn't support any of that.)
 
  


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
[SOLVED] How to copy a folder with sub directories using scp sanjay87 Linux - Server 5 05-24-2012 07:40 AM
Copy a directory into another directory while ignoring specific directories or files wh33t Linux - Newbie 14 05-16-2012 09:13 PM
Copy certain file types recursively while maintaining file structure on destination? rockf1bull Linux - Newbie 1 06-14-2011 10:28 AM
removeing the files but tree structure should be same dina3e Linux - Newbie 1 03-23-2008 06:57 AM
useing SCP to copy entire directories with sub folders? Lleb_KCir Linux - General 5 09-13-2005 10:08 PM


All times are GMT -5. The time now is 02:13 PM.

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