Files have same size

Hello,

I want remove files have same size in a directory.
this command only find this files.

ls -l | awk '$1!~/^d/{if(size[$5]!=""){ print}size[$5]=$8}'

I want to remove the files of the same size.
samples: 5 files are same size. I want to keep only first file.

Thank you very much for your help.

Assuming your ls gives column 5 as file size. And you are not checking file names is they are same or not.

Below you will get files which have size same. And first file is already removed.

Please check result first then you can just add rm to it..:slight_smile:

ls -l | awk '$1!~/^d/{if(!x[$5]){x[$5]++}else{print $NF}}'
1 Like

This may be a random approach as it depends on how your files are listed by ls . Proposal on hand reverses the order of files and prints the last name of files of identical size, then. BTW, file name is $9 on my ls -l version.To remove files, use command substitution like $(...):

ls -lr | awk '
                $1!~/^d/ {++size[$5]; name[$5]=$9}
                END {for (i in size) if (size > 1) print name}
                '

Thank you very much :slight_smile: