LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training 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-27-2013, 09:03 AM   #1
TL23
LQ Newbie
 
Registered: Jun 2013
Location: Durban
Distribution: Ubuntu
Posts: 3

Rep: Reputation: Disabled
Copy folder using find mkdir and copy


I have complex folder structure and only want to copy a subfolder and its contents that I have been working on to a new directory

for example:
/data/group1/nmr/exp1/20/pdata/1..
/data/group1/nmr/exp1/20/pdata/10..
/data/group1/nmr/exp1/40/pdata/1..
/data/group1/nmr/exp1/40/pdata/10..

I want to copy
/data/group1/exp1/40/pdata/10..
to
/data/group2/exp1/40/pdata/10..

I have up to a hundred exp# with the same subfolders and only want to target the pattern ..40/pdata/10
so I
#cd /data/group1/nmr/
#find -path ./*/40/pdata/10 -type d -exec cp "{}" /data/group2/nmr/"{}" \;
but this wont work because destination looks like this:
/data/group2/nmr/.exp1/40/pdata/10
So How do I copy contents of folder 10 (keeping the parent architecture that 10 is in to a new parent directory (group2)? In other words I need to remove the "." of my destination

I have had success with making the directory architecture without files in the folders:
#find . -type d -name "10" -exec mkdir -p -- /group1/nmr/"{}" \;
AND
I have found success in copying a subfolder 1 to a new folder 10 in the same directory by:
#find -path .*/40/pdata -type d -exec cp "{}/1" "{}/10" \;

Last edited by TL23; 06-27-2013 at 09:14 AM.
 
Old 06-27-2013, 10:34 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Why not just use "cp -r src dest"?
 
Old 06-27-2013, 10:57 AM   #3
TL23
LQ Newbie
 
Registered: Jun 2013
Location: Durban
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: Disabled
because then I would have to delete all sufolders with .../20/pdata/1.. ../20/pdata/10 ..40/pdata/1..
and the list goes on ../999/pata/* and .../998/pdata/* so forth

So I just want to focus on copying my experiments that have the subfolders...40/pdata/10/* and copy only that keeping the architecture otherwise the programme I use wont find my files - it uses this very specific architecture
 
Old 06-27-2013, 01:59 PM   #4
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,713

Rep: Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279Reputation: 1279
Quote:
Originally Posted by TL23 View Post
because then I would have to delete all sufolders with .../20/pdata/1.. ../20/pdata/10 ..40/pdata/1..
and the list goes on ../999/pata/* and .../998/pdata/* so forth

So I just want to focus on copying my experiments that have the subfolders...40/pdata/10/* and copy only that keeping the architecture otherwise the programme I use wont find my files - it uses this very specific architecture
Only if you copied them in the first place. That is what file globbing is for.
 
1 members found this post helpful.
Old 06-27-2013, 02:13 PM   #5
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 361

Rep: Reputation: 157Reputation: 157
[deleted a long and unnecessary digression on rsync]

Last edited by Beryllos; 06-27-2013 at 02:33 PM. Reason: found a better way, see below
 
Old 06-27-2013, 02:32 PM   #6
Beryllos
Member
 
Registered: Apr 2013
Location: Massachusetts
Distribution: Debian
Posts: 361

Rep: Reputation: 157Reputation: 157
Quote:
Originally Posted by jpollard View Post
Only if you copied them in the first place. That is what file globbing is for.
Oh, how I hate to make a fool of myself. jpollard's remark reminded me to read the manual (man cp) and here's what I got:
Code:
cp -vr --parents exp*/40/pdata/10 ../../group2/nmr/
Omit the -v switch if you do not need to see what happened to every file.
 
1 members found this post helpful.
Old 06-28-2013, 07:04 AM   #7
TL23
LQ Newbie
 
Registered: Jun 2013
Location: Durban
Distribution: Ubuntu
Posts: 3

Original Poster
Rep: Reputation: Disabled
Perfect Thanks berryloss I tried that and it worked... I began playing around with cpio (got various complaints about chmod permissions but still worked)

find -path .*/40/pdata/10/* -type f | cpio -pdv /data/group2/nmr
 
Old 06-28-2013, 11:45 AM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian + kde 4 / 5
Posts: 6,834

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
A more general technique is start by building an array with the directory names you want to work on. Then you can loop over them to modify the names, copy subfiles, or whatever.
 
  


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] Find all files owned by a user and copy them to a temp folder mikezoch Linux - Newbie 3 11-28-2011 07:02 PM
[SOLVED] Using terminal command -Find files in a folder and copy them to a different folder j-jock Linux - General 4 11-28-2011 03:20 AM
Scripts to list folder contents and copy images from folder and subfolders brunces Linux - Newbie 6 11-03-2011 02:23 PM
want to copy an inode folder from acdrom to a home directory (folder). nhbob Linux - Newbie 8 12-20-2009 12:12 PM
Find files and copy the results to desired folder? colbert Linux - Newbie 6 11-09-2008 12:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:30 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