1

I have a bunch of directories in a structure like this:

-Music
  -Artist1
    -Album1
    -Album2
  -Artist2
    -Album1
    -Album3
  -Artist3
    -Album2
    -Album4

All the directories will contain unique files. I would like to reorganise this directory so that the artist directories are removed from the structure:

-Music
  -Album1
  -Album2
  -Album3
  -Album4

I was thinking of a pattern like ^[^\/]+\/ but I'm terrible at regex, and how to make it actually do something with the mv command.

2
  • Your Album1 of Artist1 will replace Album1 of Artist2 and this would happen to all multiple copies. Is that good for you? – vishram0709 Nov 21 '13 at 13:07
  • yep, I expect the new Album1 to contain files that were in any of the old Album1 directories – Matthew Sainsbury Nov 21 '13 at 16:23
2

If you have enough space to temporary make a copy you can simply try this:

mkdir Music_new
cp -R Music/*/* Music_new
1
  • You don't need a temp copy, just do mv Music/*/* Music_new && mv Music_new Music. – terdon Jan 6 '14 at 11:43
1
cd Music #Go to Music
mv */* . #Move all Album directories to Music
rmdir *  #Delete all empty directories, that is, Artist ones
0
0

You can use this.

mv Music/*\/* Music/

and then you can remove Album directories.

1
  • You don't need (or want) to escape the /. – terdon Jan 6 '14 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.