Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
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

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

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

You can use this.

mv Music/*\/* Music/

and then you can remove Album directories.

share|improve this answer
    
You don't need (or want) to escape the /. – terdon Jan 6 '14 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .