awk删除重复文件

#!/bin/bash

#查找并删除重复文件,每个文件只保留1份

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=$1;

if ( csum1==csum2 )

{

print name1; print name2

}

};

size=$5;name1=name2;

}' | sort -u > duplicate_files

 

cat duplicate_files | xargs -I {} md5sum {} | \

sort | uniq -w 32 | awk '{ print $2 }' | \

sort -u > unique_files

 

echo Removing..

comm duplicate_files unique_files -3 | tee /dev/stderr | \

xargs rm

echo Removed duplicates files successfully.

 

脚本执行: bash 文件

chmod 755 文件

$ ./文件

posted @ 2019-03-15 12:25  zhg1016  阅读(190)  评论(0编辑  收藏  举报