Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash/Shell-Move all files from subdirectories into target directory?

How do I bash a command or a shell script to move all the files from the subdirectories to one target directory in Linux?

like image 569
alvas Avatar asked Dec 19 '11 12:12

alvas


2 Answers

If you are using GNU mv, the -t option (target directory) is pretty useful:

find sourcedir -type f -print0 | xargs -0 mv -t target 

man mv gives more details.

like image 95
thiton Avatar answered Nov 15 '22 21:11

thiton


Try something like this:

find sourcedir -type f -exec mv {} targetdir \;  
like image 21
John P Avatar answered Nov 15 '22 21:11

John P