我写过的最长的命令 根据md5的值找出相同的文件;所有相同的文件中只保留(任意,这里是排序后的第一)一个,删除其他,并且在数据库中把对删除文件的引用改为对保留文件的引用。
1
2 # check images: remove duplicates, update reference to removed ones in database
3
4 find /data/lessondev -type f /( -name '*png' -or -name '*jpg' /) -exec md5sum {} + |sort | uniq -D -w 32 | awk '
5 BEGIN { ORS = ""; OFS = "" }
6 {
7 if ( md5 != $1 )
8 {
9 print "/"impossible filename/");/n"
10 print "UPDATE `media` SET `Filename`= /"", $2, "/" WHERE `Filename` IN ("
11 }
12 else
13 {
14 print "/"", $2, "/", "
15 }
16 md5 = $1
17 }
18 END { print "/"impossible filename/");/n" }
19 ' | sed '1d;s#/data/lessondev/##g' | mysql -s -u username --password=mypass currdb
20
21