David Carek
David Carek

Reputation: 1113

How to copy files if size nonzero in shell?

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?

Upvotes: 5

Views: 3178

Answers (1)

anubhava
anubhava

Reputation: 785196

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.

Upvotes: 4

Related Questions