#!/bin/bash
#!当前文件夹下,删除内容相同的重复文件,只保留重复文件中的一个。
ls -lS --time-style=long-iso | awk 'BEGIN{
getline;getline;
name1=$8;size=$5
}
{
name2=$8;
if( size==$5 )
{
"md5sum " name1 | getline;csum1=$1;
"md5sum " name2 | getline;csum2=$2;
if( csum1==csum2 )
{
print name1;print name2
}
};
szie=$5;name1=name2;
}' | sort -u > duplicate_files
cat duplicate_files | xargs -i md5sum {} | uniq -w 32 | awk '{ print $2 }' | sort -u > duplicate_sample
echo removing...
comm duplicate_files duplicate_sample -2 -3 | tee /dev/stderr | xargs rm -f
echo removed successfully