Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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 directory : ../Music with a lot of music files in a lot of subdirectories.

How would i move all the files in the subdirectories to another directory ?
Thus, i only want to move the files, i don't want to keep the subdirectory structure.

share|improve this question
@iamsid Aah, i didn't check the unix.stackexchange to be honest, there's some great answers in there too :) – Aerus Jan 6 '11 at 10:54
up vote 9 down vote accepted

Assuming the current directory has the subfolders, replace TARGET_DIR in the following statement in use it:

find . -name '*.mp3' -exec mv {} TARGET_DIR \;
share|improve this answer
Nice, i knew it could be done by using find, but my knowledge of the commands in unix is somewhere burried deep inside. Thanks! – Aerus Jan 6 '11 at 10:57
@Aerus you're welcome. And not to sound pretentious, but when you know which command to use, you're only a "man command" away from knowing how to use it. – chris Jan 6 '11 at 12:27
Oh, i knew i could find all the files in the subdirectories with the find command, but i thought i then would just have list of them, which i then needed to process. I forgot about the exec, which is basically why i didn't check out the man page for find :) (Of course, if i would have checked it out, i would have found out about the exec ) – Aerus Jan 6 '11 at 14:39
@Aerus Give a read. It'll give you a good idea about what other tasks find can be used for. – geirha Feb 29 '12 at 20:27
With GNU find you can avoid spawning a new mv process for each file to move: find ../Music \( -name \*.mp3 -o -name \*.ogg \) -exec mv -t [TARGET_DIR] -- \{\} +. Alternatively with POSIX find: find ../Music \( -name \*.mp3 -o -name \*.ogg \) -print0 | xargs -0 -- mv -t [TARGET_DIR] --. – David Foerster Dec 21 '14 at 0:27

Try this:

 cd ../Music

 for i in `ls -Q`; do  mv $i/* /Path/To/Some/Other/Directory;   done

I would suggest to use cp instead of mv to check whether it is working fine or not. and if it is working fine just delete the ..Music directory

Edit: added -Q (and needed to add this explanation to get beyond six characters)

share|improve this answer
I'll see if i can use cp (i don't know if i have enough space on my ubuntu partition because i believe it's 150GB+ of music :) ), thanks for the hint! – Aerus Jan 6 '11 at 10:59
Eeek. This is quite wrong actually as it doesn't consider blanks in filenames. I edited in a -Q as parameter to the ls ... – 0xC0000022L Feb 29 '12 at 18:18
Never parse ls output. Use a glob. See – geirha Feb 29 '12 at 20:24

The first answer is correct, but an easier way to do it, assuming you only have one layer of subdirectories, is:

mv ../Music/*/*.mp3 [insert target dest here]
share|improve this answer
This could better be used as a comment. – Virusboy Dec 21 '14 at 0:27
I don't have enough reputation to comment on others' posts, but yes, perhaps. – argarevarg Dec 21 '14 at 0:28
@Virusboy: I think it's a valid answer that hasn't occurred here yet. – David Foerster Dec 21 '14 at 0:29

You could also use Rhythmbox, banshee, or a similar software. They can scan your music directories.

You can choose to preserve the directory or (in your case) the software can move the files in to a rhythmbox/banshee directory which would eliminate the hierarchy like you wanted.


cp /target/directory/* /desination/directory/ -r

Then, delete the original if it was successful.

share|improve this answer
(cd ~/Music ; tar cf - ) | (cd /path/to/other/directory; tar xf -) 
share|improve this answer
That's copy, not move. – 0xC0000022L Feb 29 '12 at 18:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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