Linux Shell枚举目录下相同文件脚本

2016年08月20日

原创内容,转载请注昨出处: https://www.myzhenai.com.cn/post/2269.html https://www.myzhenai.com/thread-17910-1-1.html
关键词: Linux查找相同文件 shell查找相同文件
写这个脚本是为了练习shell编程的,本来思路是想着通过文件大小一致和md5值一致来获取相同的文件的,但我这脚本的实现方法好像不是太严谨,应该说是不太准确的,对于是不是这样,我也没有太大的把握,因为我调试过好多遍了,但找出来好多不同文件名,但相同类型的文件,因为这些文件我知道,有好多是我拍摄的相片, 如果说文件大小有可能会一致,但每个文件的md5值应该是不一样的. 所以这里只提供给朋友们一个思路, 您也可以帮忙调试改进, 欢迎朋友们参与讨论. 说实在的,这个脚本对于我们做站的朋友们来说还是有用处的,可以清除一些网站用户上传的相同的文件.

# !/bin/bash
echo -e  "\033[31m Please enter your name you want to find the file suffix: \033[0m"
read name
dir=$(cd `dirname $0`; pwd)
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
files=`find $dir -iname "*.$name"`
for file in $files
do
size=`ls -l $file|awk '{print $5}'`
md=`md5sum $file|cut -d ' ' -f1`
echo $file" | "$size" | "$md >> tong.log
done
########################################
files=`find $dir -iname "*.$name"`
for file in $files
do
size=`ls -l $file|awk '{print $5}'`
md=`md5sum $file|cut -d ' ' -f1`
h=`grep -c $size" | "$md tong.log`
if [ $h -gt 2 ];then
echo $file"  Similarfiles  [$h]" >> long.log
fi
done
IFS=$SAVEIFS
#echo "$IFS" | od -t x1

 

Linux Shell枚举目录下相同文件脚本

Linux Shell枚举目录下相同文件脚本


Linux Shell枚举目录下相同文件脚本

Linux Shell枚举目录下相同文件脚本


Linux Shell枚举目录下相同文件脚本

Linux Shell枚举目录下相同文件脚本


sicnature ---------------------------------------------------------------------
Your current IP address is: 3.80.211.101
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source https://www.myzhenai.com/post/2269.html

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注