Copying subdirectories of a directory to some other directory and renaming them

Hi,
I am a newbie in shell scripting. I have to copy a particular sub-directory (data) from a large no. of directories (all in the same folder) and paste them to another directory ( /home/hubble/data ) and then rename all the subdirectories (data) as the name of its parent directory.

please help. Its urgent. Thank you in advance.

From directory contraining subdirectories with "data":

find . -maxdepth 1 -type d | xargs -i bash -c "mv {}/data /home/hubble/data/`basename {}`"

can you provide us more info about the sub-directories and give a sample of them? And Besides how u want to rename them?

The subdirectory name is "data", and the directories containing it have random names all starting with 00 (eg: 001276499_results). I want to copy it into "/home/hubble/data" with every subdirectory (data) having the name of its parent directory ( 00......... _......).

Did you try my code?

yes, i tried it. unfortunately, it isn't working.. After pressing enter, just the secondary prompt string came up and nothing happened..
Also, although i dont get ur code but as you used mv command, I should say again that i want to just copy them (not move).

Solaris10 does not support maxdepth as i saw after testing. You can use cp instead of mv, Bartus' command partly worked in my test environment.

Sorry, I misunderstood. But that command would work with "cp" too, just make sure you get all the quotes and backtick characters properly.

find . -maxdepth 1 -type d | xargs -i bash -c "cp -r {}/data /home/hubble/data/`basename {}`"

ran the code again. It is giving error like:
cp: cannot stat `./data': No such file or directory
and then all the directories: ./0012....._results/data/ were omitted by cp..

---------- Post updated at 04:58 AM ---------- Previous update was at 04:47 AM ----------

ok i think i got this.. shld use -R option with cp as copying a directory...

Thank you very much for your help.. you save me :slight_smile: