Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy files if size nonzero in shell?

Tags:

shell

cp

I have some files that I want to copy from one directory to another with a shell script but I only want to copy the ones that have something in them. Right now this is what I have but it won't check to make sure that the files aren't empty. cp -f /some/folder/* /another/folder/ Is there an easy way to do this?

like image 520
David Carek Avatar asked Sep 26 '22 01:09

David Carek


1 Answers

You can use find command for this:

find . -type f -size +0 -print0 | xargs -0 -I % cp % /dest/

-size +0 will get files with size greater than zero.

like image 61
anubhava Avatar answered Sep 30 '22 08:09

anubhava