Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Traverse directory list and flatten the structure

Status
Not open for further replies.

fzssyv

Programmer
Dec 16, 2002
1
What I am looking to do is to flatten the entire directory structure and rename the files to be distinct according to a naming convention. Typically what I have to work with is:

MasterDirectory
SubDir1
File1 ... FileX
SubDir2
File1 ... FileX
etc. (for a number of subdirectories)

I need to name the files as MasterDirectory-SubDir#-File# and put them all in the MasterDirectory.

Also, for an added twist, I also need to be able to do this where there is another directory under the SubDir# as well. Thanks for any help anyone can provide me on this.

-Scott
 
Hi,

Something to start with

for i in `find master -type f -print`; do mv $i master/`echo $i | sed -e 's!/!-!g'`; done
 
Oops ...

Forgot to say that if you have /dir1/MasterDirectory/SubDir1 structure, run the command in /dir1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top