Copy only files, not folder structure from a directory in Unix

hhh picture hhh · Oct 20, 2012 · Viewed 15.1k times · Source

I found this solution after googling here but I was horrified: too complicated solution. I am pretty sure some cp -versions have flags for this or just simple find will do. So how do you copy files, not directory structure, in Unix?

Answer

askmish picture askmish · Oct 20, 2012

find path-to-source-file-tree -type f -exec cp {} path-to-target-dir \;

That should take care of all your issues.

To customize it further you can refer: man find For example, based on date and time, file types, file owners, etc. you can customize the above statement.