Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
1  
    
@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

3 Answers 3

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 mywiki.wooledge.org/UsingFind 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

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 mywiki.wooledge.org/BashPitfalls –  geirha Feb 29 '12 at 20:24

(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

 
discard

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.