There are infinite ways of doing the following commands but here you can find some examples. They can be very useful when you need to manage a lot of files in different directories.

Using ‘find’

Delete empty files using find:

felipe@funstation $ find dir/ -type f -empty -print0 | xargs rm -f


Or create an script (to watch it before deleting those files):

felipe@funstation $ find dir/ -type f -empty -print0 | xargs -0 echo rm -f > delete_script.sh


Using ‘du’

List with size all *.txt files on a tree dir:

felipe@funstation $ du -ha dir/ | grep \.txt


Also that doesn’t match an specific size (256K):

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K"


Also add another possible value (256K or 512K):

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K" | grep -v "512K"

or:

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K\|512K"


Count how many they are:

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K\|512K" | wc -l


Get only the filenames:

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K\|512K" | cut -f 2


All in one line (remove trailing newline character):

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K\|512K" | cut -f 2 | tr "\n" " "


Delete Them:

felipe@funstation $ du -ha dir/ | grep \.txt | grep -v "256K\|512K" | cut -f 2 | tr "\n" " " | xargs rm -f


Notes: You can get errors with grep because it won’t distinct if the string is in the size or in the filename

Related in spanish: http://systemadmin.es/2009/04/uso-de-xargs-herramientas-unix-ii