poorvank
poorvank

Reputation: 7602

Move files of specific size in Ubuntu using Terminal

I want to move all the files in a specific folder having size of 0 bytes. I know that the following prints all the files with size zero bytes.

find /home/Desktop/ -size  0

But i want to move them to another folder, so i tried :

find /home/Desktop/ -size  0 | xargs -0 mv /home/Desktop/a

But that doesn't work. ? Is there any other way to do it.? What am i doing wrong?

Upvotes: 4

Views: 871

Answers (2)

wolfrevo
wolfrevo

Reputation: 7303

find default prints the file name on the standard output followed by a newline. The option -print0 prints the file name followed by a null character instead. The option -0 of xargs means that the input is terminated by a null character.

find /home/Desktop/ -size 0 -print0 | xargs -0 -I {} mv {} /home/Desktop/a

You could instead use find's option -exec

In both cases consider also using find's option -type f if you only want to find files and the option -maxdepth 1 if you do not want find to descend directories. This is specially usefull in your example since you move the found files to a subdirectory!

Upvotes: 1

anubhava
anubhava

Reputation: 785246

You can do that in find itself using -exec option:

find /home/Desktop/ -size 0 -exec mv '{}' /home/Desktop/a \;

Upvotes: 2

Related Questions