Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 08-09-2011, 07:04 AM   #1
LQ Newbie
Registered: Aug 2011
Posts: 9

Rep: Reputation: Disabled
Bash script to make 100 directory recursively with different names..

In some data processing task, i need to rearrange my data.I have my raw data in a directory(eg. c:/Data).The data is present in different directories like (eg C:/Data/Data1,C:/Data/Data2,C:/Data/Data3..).I have 100's of such data.I need to keep the processed data in (D:/New_Data) with respective names of the raw data(eg. D:/New_Data/Data1 will contain processed data from C:/Data/Data1 and D:/New_Data/Data2 will contain processed data from C:/Data/Data2 and so on..).I need to make a bash script so that it automatically creates new empty directories in the D:/New_data with similar names as in C:/Data, so that i only need to specify the path of processed data. Please help me out with such Bash script.

Old 08-09-2011, 07:19 AM   #2
Senior Member
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Not sure if that will work with bash but if you use cmd scripts:
@echo off
pushd C:\Data
if not exist D:\New_Data\nul mkdir D:\New_Data
for /f "delims==" %%a in ('dir /b/ad/oen') do if not exist "D:\New_Data\%%a\nul" mkdir "D:\New_Data\%%a"
Old 08-09-2011, 07:27 AM   #3
Senior Member
Registered: Jan 2010
Posts: 1,945

Rep: Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677Reputation: 677
Try this in bash:
cd /path/to/olddir
find . -type d -exec mkdir -p /full/path/to/newdir'{}' \;
Old 08-09-2011, 09:43 AM   #4
LQ Newbie
Registered: Aug 2011
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks a saved hell lot of time..


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
Can you make custom directory names? daweefolk Linux From Scratch 7 04-15-2010 12:45 PM
[SOLVED] bash calling recursively a script patolfo Programming 8 03-29-2010 11:38 AM
Bash script to transfer folders recursively without overwriting via FTP laurens Linux - Newbie 9 11-13-2009 07:40 AM
[SOLVED] Script: Trim all file names recursively Flukester Linux - Server 9 10-28-2009 06:37 AM
Getting directory names from a given path in Bash? ojha_riddhish Programming 10 04-13-2009 05:08 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:05 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration