Copying files from various folders to similar folder structure in another location

Hi,

I need to write a script the has to copy the files from folders and subfolders to the same folder structure located in another location.
Ex:

mainfolder1
file1,file2,file3 subfolder1(file1,etc) subfolder2(file1,etc) to another folder location of same folder structure.
rsync is not working

What have you tried

This seems ideal for rsync. Are you getting error from rsync?
Are you trying to only move files that have changed?
More details on what you have done, as SriniShoo has said, would help.

cp -r /xxx00d10/home/nettest/test2/ /xxx00d10/home/testexp1/test1/

it is copying all the files to the same location..but i want files to be copied to different sub directories with different path

---------- Post updated at 10:37 AM ---------- Previous update was at 10:30 AM ----------

i got rsync command not found . i searched for the rsync file in /etc location , it was not found in configuration files.

Look in either /usr/bin/rsync or /bin/rsync.

$ which rsync
/usr/bin/rsync

I would use:

/bin/rsync -av /xxx00d10/home/nettest/test2/* /xxx00d10/home/testexp1/test1

Rsync file is not located in both the places you mentioed.. I am still getting rsync not found command

rsync -av is not overwriting the files in destination

You do not state the operating system that you are using and I realize that I am joining this thread very late. So I can only answer in generic Unix speak and I might not understand your question fully.

However, if you want to copy a complete file structure to another location you can do that with 'find' and 'cpio'.

For example, assume your 'source' directory is /a/b/c and you want to copy the content of that, and all sub-directories and files, to another location such as /x/y/z then you can:

 
 cd /a/b/c
 find . -print|cpio -puvdm /x/y/z
  

Of course, you need the access rights to read/write all the files (unless you are 'root') and the directory /x/y/z MUST exist before the command is run.

Therefore, you could create a script with <source> and <destination> directories as command line arguments, and ensuring <destination> location exists before the copy is done.

I sometimes use this technique to make a live copy (backup) of files before I mess with them (if I don't want to employ tar, cpio, or other proper backup utility).

Does that help? Or have I completely missed the point?