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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Copying subdirectories of a directory to some other directory and renaming them
# 1  
Old 06-29-2010
Data 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.
# 2  
Old 06-29-2010
From directory contraining subdirectories with "data":
Code:
find . -maxdepth 1 -type d | xargs -i bash -c "mv {}/data /home/hubble/data/`basename {}`"

# 3  
Old 06-29-2010
Quote:
Originally Posted by sholay
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.
can you provide us more info about the sub-directories and give a sample of them? And Besides how u want to rename them?
# 4  
Old 06-29-2010
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......... _......).
# 5  
Old 06-29-2010
Quote:
Originally Posted by sholay
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?
# 6  
Old 06-29-2010
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).
# 7  
Old 06-29-2010
Quote:
Originally Posted by sholay
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Copying files to a directory, renaming it if a file with the same name already exists

Hi All, I need to copy files from one directory to another with the files to be renamed while copying if a file with the same name already exists in the target directory. THanks, Dev (2 Replies)
Discussion started by: dev.devil.1983
2 Replies

2. Shell Programming and Scripting

Copying files from one directory to another, renaming duplicates.

Below is the script i have but i would like simplified but still do the same job. I need a script to copy files not directories or sub-directories into a existing or new directory. The files, if have the same name but different extension; for example 01.doc 01.pdf then only copy the .doc file. ... (1 Reply)
Discussion started by: Gilljambo
1 Replies

3. UNIX for Dummies Questions & Answers

Renaming files with part of their pathname and copying them to new directory

Hi I think this should be relatively simple but I can't figure it out. I have several files with the same name in different folders within a directory (the output of a program that I ran). Something like this: ./myAnalysis/item1/round1/myoutput.txt ./myAnalysis/item1/round2/myoutput.txt... (2 Replies)
Discussion started by: jullee
2 Replies

4. UNIX for Dummies Questions & Answers

recursive copy into a directory and all its subdirectories...

I want to copy a file from the top directory into all the sub-folders and all of the sub-folders of those sub-folder etc. Does anyone have any idea how to do this? Thanks in advance of any help you can give. (3 Replies)
Discussion started by: EinsteinMcfly
3 Replies

5. Shell Programming and Scripting

Find directory name while traversing subdirectories

Hi, I have a parent directory in which I have sub directories of different depth /usr/usr1/user2/671 /usr/usr1/672 /usr/user2/user1/673 /usr/user2/user3/user4/674 And I need the names of all the directories that which starts only with 6 in a file. Thanks, (12 Replies)
Discussion started by: arun_maffy
12 Replies

6. UNIX for Dummies Questions & Answers

How to remove directory with subdirectories and files?

I'm trying to remove several directories which contains sun-dirs and files inside. I used the command rm -r <dirname> But, it always ask "examine file in directory <dirname> yes/no?" line by line. So, i need to write "y" for every line. How can i skip this step and remove all directories with... (9 Replies)
Discussion started by: ppa108
9 Replies

7. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies

8. UNIX for Dummies Questions & Answers

Copying one file at a time from one directory to another directory.

Hi All i want to write a script which could copy one file at a time from one directory to another directory. Scenerio: Let's say i have 100 file in a dirctory,so i want to copy one file at a time to another directory with a sleep statement in between that of 30 secs. please help me... (1 Reply)
Discussion started by: Nikhilindurkar
1 Replies

9. Shell Programming and Scripting

How Can I Make Subdirectories In A Directory?

I cant remember how, i use to know but its been like 2 years since ive used shell can anyone help me? (7 Replies)
Discussion started by: kprescod4158
7 Replies

10. UNIX for Dummies Questions & Answers

makefiles in a directory and subdirectories

I need to develop a makefile that spans across directories. For example, let's say i have an upper level directory (main) and about 2 subdirectories. I want my .cpp files and .o files to be in one subdirectory. I want my .a files to be in the other subdirectory. The .a files are made up of the... (0 Replies)
Discussion started by: benjie_asu
0 Replies
Login or Register to Ask a Question