Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

unix

cp

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?

like image 593
hhh Avatar asked Dec 06 '25 20:12

hhh


2 Answers

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.

like image 75
askmish Avatar answered Dec 09 '25 17:12

askmish


I would use find, cannot find a flag in my GNU Coreutils 8.5 cp about not-preserving directory-structure. Anyway the one-liner:

find . -type f -exec cp '{}' ~/Backup/ \;
like image 36
hhh Avatar answered Dec 09 '25 17:12

hhh