This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Linux command to delete empty fastq.gz files

Hi all,

I am wondering how to use Linux command to remove all the fastq.gz files within a folder.

As the compressed fastq.gz has a size of 20 bytes even if it's empty after decompressing, I am not sure how to delete (and list) them.

I tried to list them when I was in the folder - but somehow find . -size 20 returned nothing. However, ls -l did tell me there were a bunch of size 20 fastq.gz files.

Here is an example of a set of "empty" fastq.gz files:

 gzip --list xxxxxxx.gz
         compressed        uncompressed  ratio uncompressed_name
                 20                   0   0.0% xxxxxxx.fastq

Thank you so much!

linux fastq gz

I think you are missing c option for bytes.

$ find . -type f -name "*.gz" -size 20c -exec rm -i {} \;

If you want to remove any file of size 20 bytes and under try:

$ find . -type f -name "*.gz" -size -20c -exec rm -i {} \;

To be safe, please filter by file extension and use -i after rm.

1 answer

You could use the - flag to get files smaller than a small size, for example for 20 bytes:

find . -size -20c 

will give you all files smaller (-) than 20 bytes (c).

Log in to answer this question.