Hầu hết người dùng máy tính đều có yêu cầu chung là tìm và thay thế các tệp trùng lặp. Tìm và loại bỏ các tập tin trùng lặp là một công việc mệt mỏi đòi hỏi thời gian và sự kiên nhẫn. Việc tìm kiếm các tệp trùng lặp có thể rất dễ dàng nếu máy của bạn chạy GNU/Linux, nhờ vào ‘fdupes ‘ tiện ích.
Fdupes – Tìm và xóa các tệp trùng lặp trong Linux Fdupes là gì?
Những kẻ lừa đảo là một tiện ích Linux được viết bởi Adrian Lopez trong C Ngôn ngữ lập trình được phát hành theo Giấy phép MIT. Ứng dụng có thể tìm thấy các tệp trùng lặp trong tập hợp các thư mục và thư mục con nhất định. Fdupes nhận dạng các bản sao bằng cách so sánh chữ ký MD5 của các tệp, sau đó là so sánh từng byte. Rất nhiều tùy chọn có thể được thông qua với Fdupes để liệt kê, xóa và thay thế các tệp bằng liên kết cứng thành các bản sao.
Việc so sánh bắt đầu theo thứ tự:
so sánh kích thước> So sánh chữ ký MD5 một phần> So sánh chữ ký MD5 đầy đủ> So sánh từng byte .
Cài đặt fdupes trên Linux
Cài đặt phiên bản fdupes mới nhất (fdupes phiên bản 1.51) dễ dàng bằng cách chạy lệnh sau trên Debian các hệ thống dựa trên nền tảng như Ubuntu và Linux Mint .
$ sudo apt-get install fdupes
Trên CentOS /RHEL và Fedora dựa trên hệ thống, bạn cần bật kho lưu trữ epel để cài đặt gói fdupes.
# yum install fdupes # dnf install fdupes [On Fedora 22 onwards]
Lưu ý :Trình quản lý gói mặc định yum được thay thế bằng dnf từ Fedora 22 trở đi…
Cách sử dụng lệnh fdupes?
1. Với mục đích trình diễn, hãy tạo một vài tệp trùng lặp trong một thư mục (giả sử tecmint ) đơn giản là:
$ mkdir /home/"$USER"/Desktop/tecmint && cd /home/"$USER"/Desktop/tecmint && for i in {1..15}; do echo "I Love Tecmint. Tecmint is a very nice community of Linux Users." > tecmint${i}.txt ; done
Sau khi chạy lệnh trên, hãy kiểm tra xem các tệp trùng lặp đã được tạo hay chưa bằng lệnh ls.
$ ls -l total 60 -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint10.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint11.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint12.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint13.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint14.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint15.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint1.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint2.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint3.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint4.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint5.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint6.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint7.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint8.txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9.txt
Đoạn script trên tạo 15 các tệp cụ thể là tecmint1.txt, tecmint2.txt…tecmint15.txt và mọi tệp đều chứa cùng một dữ liệu, tức là
"I Love Tecmint. Tecmint is a very nice community of Linux Users."
2. Bây giờ hãy tìm kiếm các tệp trùng lặp trong thư mục tecmint .
$ fdupes /home/$USER/Desktop/tecmint /home/tecmint/Desktop/tecmint/tecmint13.txt /home/tecmint/Desktop/tecmint/tecmint8.txt /home/tecmint/Desktop/tecmint/tecmint11.txt /home/tecmint/Desktop/tecmint/tecmint3.txt /home/tecmint/Desktop/tecmint/tecmint4.txt /home/tecmint/Desktop/tecmint/tecmint6.txt /home/tecmint/Desktop/tecmint/tecmint7.txt /home/tecmint/Desktop/tecmint/tecmint9.txt /home/tecmint/Desktop/tecmint/tecmint10.txt /home/tecmint/Desktop/tecmint/tecmint2.txt /home/tecmint/Desktop/tecmint/tecmint5.txt /home/tecmint/Desktop/tecmint/tecmint14.txt /home/tecmint/Desktop/tecmint/tecmint1.txt /home/tecmint/Desktop/tecmint/tecmint15.txt /home/tecmint/Desktop/tecmint/tecmint12.txt
3. Tìm kiếm các bản sao đệ quy trong mọi thư mục bao gồm các thư mục con bằng cách sử dụng -r tùy chọn.
Nó tìm kiếm đệ quy trên tất cả các tệp và thư mục, tùy thuộc vào số lượng tệp và thư mục, sẽ mất một chút thời gian để quét các bản sao. Trong thời gian đó, bạn sẽ được cung cấp tổng tiến độ trong thiết bị đầu cuối, đại loại như thế này.
$ fdupes -r /home Progress [37780/54747] 69%
4. Xem kích thước của các bản sao được tìm thấy trong một thư mục bằng cách sử dụng -S tùy chọn.
$ fdupes -S /home/$USER/Desktop/tecmint 65 bytes each: /home/tecmint/Desktop/tecmint/tecmint13.txt /home/tecmint/Desktop/tecmint/tecmint8.txt /home/tecmint/Desktop/tecmint/tecmint11.txt /home/tecmint/Desktop/tecmint/tecmint3.txt /home/tecmint/Desktop/tecmint/tecmint4.txt /home/tecmint/Desktop/tecmint/tecmint6.txt /home/tecmint/Desktop/tecmint/tecmint7.txt /home/tecmint/Desktop/tecmint/tecmint9.txt /home/tecmint/Desktop/tecmint/tecmint10.txt /home/tecmint/Desktop/tecmint/tecmint2.txt /home/tecmint/Desktop/tecmint/tecmint5.txt /home/tecmint/Desktop/tecmint/tecmint14.txt /home/tecmint/Desktop/tecmint/tecmint1.txt /home/tecmint/Desktop/tecmint/tecmint15.txt /home/tecmint/Desktop/tecmint/tecmint12.txt
5. Bạn có thể xem kích thước của các tệp trùng lặp cho mọi thư mục và thư mục con gặp phải bằng cách sử dụng -S và -r các tùy chọn cùng một lúc, như:
$ fdupes -Sr /home/avi/Desktop/ 65 bytes each: /home/tecmint/Desktop/tecmint/tecmint13.txt /home/tecmint/Desktop/tecmint/tecmint8.txt /home/tecmint/Desktop/tecmint/tecmint11.txt /home/tecmint/Desktop/tecmint/tecmint3.txt /home/tecmint/Desktop/tecmint/tecmint4.txt /home/tecmint/Desktop/tecmint/tecmint6.txt /home/tecmint/Desktop/tecmint/tecmint7.txt /home/tecmint/Desktop/tecmint/tecmint9.txt /home/tecmint/Desktop/tecmint/tecmint10.txt /home/tecmint/Desktop/tecmint/tecmint2.txt /home/tecmint/Desktop/tecmint/tecmint5.txt /home/tecmint/Desktop/tecmint/tecmint14.txt /home/tecmint/Desktop/tecmint/tecmint1.txt /home/tecmint/Desktop/tecmint/tecmint15.txt /home/tecmint/Desktop/tecmint/tecmint12.txt 107 bytes each: /home/tecmint/Desktop/resume_files/r-csc.html /home/tecmint/Desktop/resume_files/fc.html
6. Ngoài việc tìm kiếm đệ quy trong một thư mục hoặc tất cả các thư mục, bạn có thể chọn hai hoặc ba thư mục theo yêu cầu. Chưa kể bạn có thể sử dụng tùy chọn -S và/hoặc -r nếu được yêu cầu.
$ fdupes /home/avi/Desktop/ /home/avi/Templates/
7. Để xóa các tệp trùng lặp trong khi bảo quản một bản sao, bạn có thể sử dụng tùy chọn '-d' . Cần hết sức cẩn thận khi sử dụng tùy chọn này, nếu không bạn có thể mất các tệp/dữ liệu cần thiết và lưu ý rằng quá trình này không thể phục hồi được.
$ fdupes -d /home/$USER/Desktop/tecmint [1] /home/tecmint/Desktop/tecmint/tecmint13.txt [2] /home/tecmint/Desktop/tecmint/tecmint8.txt [3] /home/tecmint/Desktop/tecmint/tecmint11.txt [4] /home/tecmint/Desktop/tecmint/tecmint3.txt [5] /home/tecmint/Desktop/tecmint/tecmint4.txt [6] /home/tecmint/Desktop/tecmint/tecmint6.txt [7] /home/tecmint/Desktop/tecmint/tecmint7.txt [8] /home/tecmint/Desktop/tecmint/tecmint9.txt [9] /home/tecmint/Desktop/tecmint/tecmint10.txt [10] /home/tecmint/Desktop/tecmint/tecmint2.txt [11] /home/tecmint/Desktop/tecmint/tecmint5.txt [12] /home/tecmint/Desktop/tecmint/tecmint14.txt [13] /home/tecmint/Desktop/tecmint/tecmint1.txt [14] /home/tecmint/Desktop/tecmint/tecmint15.txt [15] /home/tecmint/Desktop/tecmint/tecmint12.txt Set 1 of 1, preserve files [1 - 15, all]:
Bạn có thể nhận thấy rằng tất cả các bản sao đều được liệt kê và bạn được nhắc xóa từng cái một hoặc một phạm vi nhất định hoặc tất cả cùng một lúc. Bạn có thể chọn một phạm vi giống như bên dưới để xóa các tệp thuộc phạm vi cụ thể.
Set 1 of 1, preserve files [1 - 15, all]: 2-15 [-] /home/tecmint/Desktop/tecmint/tecmint13.txt [+] /home/tecmint/Desktop/tecmint/tecmint8.txt [-] /home/tecmint/Desktop/tecmint/tecmint11.txt [-] /home/tecmint/Desktop/tecmint/tecmint3.txt [-] /home/tecmint/Desktop/tecmint/tecmint4.txt [-] /home/tecmint/Desktop/tecmint/tecmint6.txt [-] /home/tecmint/Desktop/tecmint/tecmint7.txt [-] /home/tecmint/Desktop/tecmint/tecmint9.txt [-] /home/tecmint/Desktop/tecmint/tecmint10.txt [-] /home/tecmint/Desktop/tecmint/tecmint2.txt [-] /home/tecmint/Desktop/tecmint/tecmint5.txt [-] /home/tecmint/Desktop/tecmint/tecmint14.txt [-] /home/tecmint/Desktop/tecmint/tecmint1.txt [-] /home/tecmint/Desktop/tecmint/tecmint15.txt [-] /home/tecmint/Desktop/tecmint/tecmint12.txt
8. Từ quan điểm an toàn, bạn có thể muốn in kết quả của 'fdupes' vào tệp và sau đó kiểm tra tệp văn bản để quyết định tệp nào cần xóa. Điều này làm giảm khả năng tập tin của bạn vô tình bị xóa. Bạn có thể làm:
$ fdupes -Sr /home > /home/fdupes.txt
Lưu ý :Bạn có thể thay thế '/home' với thư mục bạn muốn. Đồng thời sử dụng tùy chọn ‘-r’ và '-S' nếu bạn muốn tìm kiếm đệ quy và Kích thước in tương ứng.
9. Bạn có thể bỏ qua tệp đầu tiên trong mỗi bộ kết quả khớp bằng cách sử dụng tùy chọn '-f' .
Danh sách đầu tiên các tập tin của thư mục.
$ ls -l /home/$USER/Desktop/tecmint total 20 -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (3rd copy).txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (4th copy).txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (another copy).txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9 (copy).txt -rw-r--r-- 1 tecmint tecmint 65 Aug 8 11:22 tecmint9.txt
rồi bỏ qua tệp đầu tiên trong mỗi bộ kết quả phù hợp.
$ fdupes -f /home/$USER/Desktop/tecmint /home/tecmint/Desktop/tecmint9 (copy).txt /home/tecmint/Desktop/tecmint9 (3rd copy).txt /home/tecmint/Desktop/tecmint9 (another copy).txt /home/tecmint/Desktop/tecmint9 (4th copy).txt
10. Kiểm tra phiên bản fdupes đã cài đặt.
$ fdupes --version fdupes 1.51
11. Nếu bạn cần bất kỳ trợ giúp nào về fdupes, bạn có thể sử dụng switch '-h' .
$ fdupes -h Usage: fdupes [options] DIRECTORY... -r --recurse for every directory given follow subdirectories encountered within -R --recurse: for each directory given after this option follow subdirectories encountered within (note the ':' at the end of the option, manpage for more details) -s --symlinks follow symlinks -H --hardlinks normally, when two or more files point to the same disk area they are treated as non-duplicates; this option will change this behavior -n --noempty exclude zero-length files from consideration -A --nohidden exclude hidden files from consideration -f --omitfirst omit the first file in each set of matches -1 --sameline list each set of matches on a single line -S --size show size of duplicate files -m --summarize summarize dupe information -q --quiet hide progress indicator -d --delete prompt user for files to preserve and delete all others; important: under particular circumstances, data may be lost when using this option together with -s or --symlinks, or when specifying a particular directory more than once; refer to the fdupes documentation for additional information -N --noprompt together with --delete, preserve the first file in each set of duplicates and delete the rest without prompting the user -v --version display fdupes version -h --help display this help message
Đó là tất cả bây giờ. Hãy cho tôi biết bạn đã tìm và xóa các tệp trùng lặp như thế nào cho đến nay trong Linux? và cũng cho tôi biết ý kiến của bạn về tiện ích này. Hãy đưa phản hồi có giá trị của bạn vào phần bình luận bên dưới và đừng quên thích/chia sẻ với chúng tôi để giúp chúng tôi được lan tỏa.
Tôi đang làm việc trên một tiện ích khác tên là fslint để xóa các tệp trùng lặp, sẽ sớm đăng và mọi người sẽ thích đọc.