Guest User

Untitled

a guest
Feb 16th, 2026
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. #!/bin/sh
  2. # 2 ������ 12.38 ������ �� 12'989 ������ ����� �������� 10'026'786'125 ����
  3. # (�����: 9'919'093'813 ����)
  4. # 1 ������ 13.00 ������ �� 10'399 ������ ����� �������� 27'171'656'169 ����
  5. # (�����: 26'401'660'287 ����)
  6. # 1 ������ 17.82 ������ �� 8'686 ������ ����� �������� 11'474'216'791 ����
  7. # (�����: 11'131'537'062 ����)
  8. # 3 ������ 19.77 ������ �� 16'257 ������ ����� �������� 70'697'892'519 ����
  9. # (�����: 69'132'667'051 ����)
  10. #
  11. FILELIST="/tmp/filelist_4_mysql"
  12. SQLFILE="/tmp/tmp_4_mysql"
  13. OUTP="/tmp/double_files"
  14. DB="/tmp/filelistdb"
  15.  
  16. STEP_CNTR=0
  17. #DUP_CNTR=0
  18.  
  19. if [ "$1" = "-h" ]; then
  20. echo "Usage: $(basename $0) [-h|-d|-l]"
  21. echo -e "\t-h\tshow this help"
  22. echo -e "\t-l\tmake hardlinks for duplicates"
  23. echo -e "\t-d\tdelete duplicates"
  24. exit 1
  25. fi
  26.  
  27. function SQL(){
  28. echo -e $* | sqlite3 $DB
  29. }
  30.  
  31. function SQLF(){
  32. sqlite3 $DB < $SQLFILE
  33. }
  34.  
  35.  
  36. function Step(){
  37. STEP_CNTR=$[$STEP_CNTR + 1 ]
  38. echo -e "\n\e[1;32m$STEP_CNTR\t\t$*...\e[0m"
  39. }
  40.  
  41. rm -f $FILELIST $SQLFILE $OUTP $DB
  42.  
  43. Step "Init database"
  44. SQL "create table files(filename string, filesize integer); create table dups(filename string, filemd5 long);"
  45.  
  46. Step "Making list of files"
  47. find -type f -printf "%p\t%s\n" > $FILELIST
  48.  
  49. Step "Finding files with same size"
  50. cat > $SQLFILE << EOF
  51. delete from files;
  52. .mode tabs
  53. .import /tmp/filelist_4_mysql files
  54. delete from files where filesize in (select filesize from (select filesize,count(*) c from files group by filesize having c = 1) T);
  55. delete from files where filesize = 0;
  56. select filesize from files group by filesize;
  57. EOF
  58.  
  59. SQLF > $OUTP
  60.  
  61. cat > $SQLFILE << EOF
  62. delete from dups;
  63. .mode tabs
  64. .import /tmp/filelist_4_mysql dups
  65. delete from dups where filemd5 in (select filemd5 from (select filemd5,count(*) c from dups group by filemd5 having c = 1) T);
  66. select filename from dups group by filemd5;
  67. EOF
  68.  
  69. Step "Finding duplicates"
  70. while read SIZE
  71. do
  72. rm -f $FILELIST
  73. SQL "select filename from files where filesize = $SIZE ;" | while read FILE
  74. do
  75. MD=$(sha1sum -b "$FILE" | awk '{print $1}' 2>/dev/null);
  76. if [ "$MD" != "" ]; then
  77. echo -e "$FILE\t$MD" >> $FILELIST
  78. else
  79. echo -e "\e[1;31;40mCant read MD5 of $FILE\e[0m\nTrace:"
  80. SQL "select filename from files where filesize = $SIZE;"
  81. fi
  82. done
  83. SQLF | while read FILE
  84. do
  85. echo -e "\n\e[1;41;33m$FILE\e[36m has dublicates:\e[0m"
  86. SQL "select filename from dups where filemd5 = (select filemd5 from dups where filename = \"$FILE\") AND filename != \"$FILE\";" | while read D_FILE
  87. do
  88. echo -e "\e[1;32;40m$D_FILE\e[0m"
  89. [ "$1" = "-d" ] && rm -f "$D_FILE" && echo "deleted"
  90. [ "$1" = "-l" ] && ln -f "$FILE" "$D_FILE" && echo "linked" #|| ln -fs "$FILE" "$D_FILE" || echo -e "\e[1;31;40merror linking $FILE to $D_FILE!!!\e[0m"
  91. done
  92. done
  93. done < $OUTP
  94.  
  95. Step "Deleting trash"
  96. #echo "delete from files; delete from dups;"
  97. rm -f $FILELIST $SQLFILE $OUTP $DB
  98.  
Advertisement
Add Comment
Please, Sign In to add comment