Follow this article’s guidelines to delete duplicate files on Raspberry Pi through fdupes.
Delete Duplicate Files on Raspberry Pi Using fdupes
To delete the duplicate files on Raspberry Pi using fdupes, follow the below-mentioned instructions:
Step 1: Before installing fdupes on Raspberry Pi, it is recommended to update and upgrade the Raspberry Pi repository and for that run the below-written commands in terminal:
Step 2: Then install fdupes by using the below-written command:
Step 3: After the installation, fdupes is ready to be used to find the duplicate files. Just run the following command with the path of a directory in which you want to find the duplicate files:
Syntax
Example
The above command searches the duplicate files inside the directory.
If there are so many sub-directories inside a directory; then to recursively search duplicate files, use the following command:
In the above command, the first two files are from a similar directory with the same content inside the files. The third one with the same file name is from a subdirectory with the same content inside the file.
Step 4: If you want to delete the duplicate files in any directory, use the below-mentioned command:
Syntax
Example
Step 5: After entering the above command, the list of duplicated files will appear on the screen, and a preserve file text will display at the bottom of the screen with various options:
Note: The following is the Documents’ directory content before fdupes operation:
Step 6: For the file that you want to keep (preserve), type the number of that file in front of the preserve file options, the other will get deleted automatically:
Here, I am preserving file 1 which is file3.txt and deleting the other one:
Step 7: After entering the file number, the positive (+) sign will appear with the file that will be kept and a negative (–) sign will appear with the file that will get deleted:
Step 8: Then enter the word prune and the duplicated file will get deleted:
Step 9: Once the file is deleted, you can go back to the terminal by typing the exit command:
Step 10: To confirm that the file is deleted, enter the ls command with the directory path and you will see that file which we have deleted will not be present in the list:
Syntax
Example
In this way, you can delete other duplicate files in the same way in any directory on the Raspberry Pi system.
Conclusion
fdupes can be used to find and delete the duplicate files in Raspberry Pi. Just install the fdupes from the Raspberry Pi repository using the apt command. Then use the fdupes command along with a directory name to find the duplicate files in any directory. To recursively search files in all the sub-directories fdupes is used along with -r flag and to delete the duplicated file use -d flag.