Recursive copy of Folders with files


 
Thread Tools Search this Thread
Operating Systems HP-UX Recursive copy of Folders with files
# 1  
Old 09-02-2014
HP Recursive copy of Folders with files

Dear All,

I will appreciate any help received. Our system is running on hpux v1

My problem is as follows:

We have many customer folders with name fd000100, fd000101 and so on
e.g.
Code:
(Testrun)(testsqa):/>ll /TESTrun/fd000100
total 48
drwxrwx---   2 fq000100   test         96 Jun 27  2004 ca
drwxrwx---   2 fq000100   test         96 Jun  1  2003 ipo
drwxrwx---  761 fq000100   test      20480 Aug 27 14:36 reports
drwxrwx---   2 fq000100   test         96 Jun  1  2003 settle
drwxrwx---   2 fq000100   test       4096 Feb 17  2013 sign
(Testrun)(testsqa):/>

Each customer folder has 5 sub-folders. Our target folder is reports folder.
This reports folder has many sub-folders and many files in each sub-folders.

We need to copy these reports folders with its parent folder e.g. fd000100 along with all sub-folders in it.

Say our destination path is /Testrun/new-dest

So, after copy the listing should be as follows:

Code:
(Testrun)(testsqa):/>ll /TESTrun/new-dest/fd000100
total 48
drwxrwx---  761 fq000100   test      20480 Aug 27 14:36 reports
(Testrun)(testsqa):/>

(Testrun)(testsqa):/>ll /TESTrun/new-dest/fd000101
total 48
drwxrwx---  761 fq000100   test      20480 Aug 27 14:36 reports
(Testrun)(testsqa):/>

and so on...

Any help or hints on this recursive copy command will be highly appreciated.

Thanks you in advance.

Last edited by Don Cragun; 09-02-2014 at 03:06 PM.. Reason: Add CODE and ICODE tags.
# 2  
Old 09-02-2014
Hi,

Not entirely sure what you want to do here, am I to understand that you want to copy everything to a new destination - and place the other four directories inside the reports directory.

Or am I missng something here.

Regards

dave
# 3  
Old 09-02-2014
you may use cp command with -rP optins (r for recursive; P for directory)

Code:
cp -rP fd000100 /TESTrun/new-dest/

---------- Post updated at 06:20 AM ---------- Previous update was at 06:18 AM ----------

if you already have the directory in destination folder, you may use -R option to merge the directories
# 4  
Old 09-02-2014
In the TESTrun directory, try this manually to see if it works in general as expected:
Code:
tar cvf - fd000100/reports | (cd new-dest && tar xvf -)

If the result is OK, and assuming all directories starting with fd do not contain any whitespaces, you can do the rest via for loop:
Code:
for i in fd*; do tar cvf - $i/reports | (cd new-dest && tar xvf -); done

# 5  
Old 09-02-2014
Why not
Code:
tar cvf - fd*/reports | { cd /TESTrun/ && tar xvf - ; }

(if it fits onto the command line)?
# 6  
Old 09-03-2014
We have around 700 such fd000100 folders e.g. fd000101, fd000102, fd000103 and so on. Hence manual copy is not an option. I tried
Code:
cp -rp fd*/reports /Testrun

But it does not serve my purposes. In the destination path the fd000100 folders are not present. Is it possible to create these folders while copying files?

The source directory structure is:
Code:
RUNenv/fd000100/reports/01-JAN-2014/abc.txt
RUNenv/fd000100/reports/01-JAN-2014/def.txt
.
.
.
RUNenv/fd000100/reports/02-JAN-2014/xyz.txt
.
.

There are few millions of such text files.

I am searching for a solution to copy these directory recursively with sub-folders and files to a new destination such as

/TESTrun

So, after copy the new directory should be as follows
Code:
TESTrun/fd000100/reports/01-JAN-2014/abc.txt
TESTrun/fd000100/reports/01-JAN-2014/def.txt
.
.
TESTrun/fd000100/reports/02-JAN-2014/xyz.txt


Moderator's Comments:
Mod Comment Please use code tags next time for your code and data. Thanks

Last edited by vbe; 09-03-2014 at 09:40 AM..
# 7  
Old 09-03-2014
Quote:
Is it possible to create these folders while copying files?
Well its possible to create these folder before copying files into... It means using a loop...
e.g. Using Junior-helper's code:
Code:
newdest=<where to copy>
for i in fd* 
do 
   mkdir $newdest/$i
   tar cvf - $i/reports | (cd $newdest && tar xvf -)
done

Dont ask if the code works, because I tested... But if you have issues its because you did not say all e.g. who are the owners of the dirs and files? tar will preserve them but what about $newdest/$i ?
We cant guess all.. it looks like those directories have the same name as their owner in which case you will have to do and chown and even perhaps a chmod because I cant guess what umask you have, if any...

Last edited by vbe; 09-03-2014 at 10:39 AM..
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to copy files/folders and show the files/folders?

Hi, So i know we use cp -r as a basic to copy folders/files. I would like this BUT i would like to show the output of the files being copied. With the amazing knowledge i have i have gone as far as this: 1) find source/* -exec cp -r {} target/ \; 2) for ObjectToBeCopied in `find... (6 Replies)
Discussion started by: Imre
6 Replies

2. Shell Programming and Scripting

Recursive search for files and copy to new directories

So I have extremely limited experience with shell scripting and I was hoping someone could point out a few commands I need to use in order to pull this off with a shell script like BASH or whatnot (this is on OS X). I need to search out for filenames with account numbers in the name itself... (3 Replies)
Discussion started by: flyawaymike
3 Replies

3. Shell Programming and Scripting

Loop folders, delete files, copy new ones

Folks, I am hopeful that you may be able to help me out with writing a script that can be run nightly (as cron?) to loop through all subfolders within the "/media" directory, delete all of the files in each of them, and then copy in all of the files from the "/home//sansa" directory to each of... (6 Replies)
Discussion started by: acraig
6 Replies

4. UNIX for Dummies Questions & Answers

copy mutilple files to mutiple folders

Hi, I just started to learn shell progamming and just can't get my head around the following problem. I need to do the following: I have a folder which contains 100+ subfolders. Inside these subfolders there is one folder named 'Morph' and several jpg's. I need to copy all the files into... (4 Replies)
Discussion started by: M474746
4 Replies

5. Shell Programming and Scripting

recursive saving of files and folders

Hi all I have a bash script, that loops through a folders files and all subfolders for .shtml files. It looks for a string and replaces it, creating a backup of the original file. This all works great, but I'd like, when the backup is done, that the files are then also created in their... (4 Replies)
Discussion started by: terrid
4 Replies

6. Windows & DOS: Issues & Discussions

Windows mass copy files with same name in differnt folders

I have files existing with same names in the folders with date as display below c:\2010-09-10 <==== folder arr1.jpg arr2.jpg arr3.jpg arr4.jpg c:\2010-09-09 <==== folder arr1.jpg arr2.jpg c:\2010-09-08 <==== folder arr2.jpg arr3.jpg arr4.jpg ... (5 Replies)
Discussion started by: jville
5 Replies

7. Shell Programming and Scripting

I need script Copy permissions of files and folders from one server to another

Hi.. I have 2 servers with linux suse10. I made a mistake and on one of the servers changed with chmod the permission of root in directory /. In the other servers the permissions are correct Please i need a script, to change the permissions of one server 1, using the same permission of the... (11 Replies)
Discussion started by: ave-phoenix
11 Replies

8. Shell Programming and Scripting

copy some files from users home folders to my folder

i have users home directories in /home all the users have some files starting with character e and i want to copy all these files in a folder in my (root) home using a script i tried the script for i in m5 do cd m5 cp e1* /home/pc/exam cd .. done but get these... (3 Replies)
Discussion started by: pcrana
3 Replies

9. UNIX for Dummies Questions & Answers

copy all files and folders and cjange or remove ownership

So tried: cp -r -p test1/ user@machine:///srv/www/vhosts/domain.co.uk/httpdocs/backup/ but this didn't work either :( Anyone able to help with this? Many thanks Mr M (3 Replies)
Discussion started by: misterm
3 Replies

10. UNIX for Advanced & Expert Users

recursive copy of hidden files

I need to know how to copy hidden files recursively? cp -r sourceDir/* targetDir/. ignores the hidden files. Thank you!! (2 Replies)
Discussion started by: usfrog
2 Replies
Login or Register to Ask a Question