专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

查找重复文件

百度收藏 QQ搜藏

有时候会下载好多文件,知道有重复的,但不知道是那些。下面的脚本可以找出当前目录或指定目录下所有大小相等的文件,然后配合后面两个脚本比较二进制文件。

#!/bin/bash
#email:jyhln@163.com
#msn:jyhln@msn.com
#oicq:28995895
echo -n>/tmp/result_001.tmp
echo -n>/tmp/result.tmp
if [ $# -eq 0 ];then
dir_t=`pwd`
else
dir_t=`pwd $@`
fi
ls -Rlp -o --full-time $dir_t>/tmp/filelist_001.tmp
#create tmp file

flag=100

for line in `cat /tmp/filelist_001.tmp`;do
#path
if [ "`echo $line|grep ^/|grep :$`" ];then
flag=100
dir_swap=$line
continue
fi

#size
if [ "`echo $line|grep ^[-s][r-][-w][-x][-r]`" -a $flag -gt 10 ];then
flag=2
fi

flag=` expr $flag + 1 `
if [ $flag -eq 6 ];then
size=$line
continue
fi
#file
if [ $flag -eq 10 ];then
flag=100
echo -e $"$size \t$dir_swap\b/$line">>/tmp/result_001.tmp
#echo -e $"$size \t$dir_swap $line"
fi

done

#if have the same size

for byte in `cut /tmp/result_001.tmp -f 1`
do
counter=`grep -w ^"$byte" /tmp/result_001.tmp|wc -l`

if [ $counter -gt 1 ];then
test_n=`grep ^"$byte " /tmp/result.tmp`
if [ ! "$test_n" ];then
grep ^"$byte " /tmp/result_001.tmp>>/tmp/result.tmp
echo>>/tmp/result.tmp
fi

fi
done

cat /tmp/result.tmp
rm -f /tmp/result.tmp /tmp/filelist_001.tmp /tmp/result_001.tmp

上一篇:让scroll lock指示灯闪烁 下一篇:判断二进制文件是否相同

power by soyo123 2007-2008