I have photos, in folder A, they also exist, in folders B and C. They have the same filenames. How to search for them and delete them from folder A? A perl script or something would be ideal since I don't like to download a software for this task.
5 Answers
Try this command:
find . -type f -exec cmp -s '{}' "$destdir/{}" \; -exec echo mv -v "$destdir/{}" "$ToDelete"/ \;
How to use?
Step 1: Make a temporary directory to moving duplicate files into that:
ToDelete=/tmp/ToDelete; mkdir -p "$ToDelete"
Step 2: Set destdir
to your FolderA directory which we want to delete duplicate photos from there.
destdir=/path/to/FolderA
Step 3 cd to your first source directory(FolderB) and run the command
cd /path/to/FolderB
find . -type f -exec cmp -s '{}' "$destdir/{}" \; -exec echo mv -v "$destdir/{}" "$ToDelete"/ \;
Step 4: Now cd to your next source directory(FolderC) and run again the command
cd /path/to/FolderC
find . -type f -exec cmp -s '{}' "$destdir/{}" \; -exec echo mv -v "$destdir/{}" "$ToDelete"/ \;
Ok. Now if you test the command and see the result, so remove the echo
command to moving the duplicate photos into /tmp/ToDelete
directory.
See the test below:
$ ls ~/FolderA
1.jpg 2.jpg 6.jpg 7.jpg 8.jpg
$ ls ~/FolderB
3.jpg 4.jpg 5.jpg 7.jpg 8.jpg 9.jpg
$ ls ~/FolderC
6.jpg 7.jpg 8.jpg 9.jpg
$ ToDelete=/tmp/ToDelete; mkdir -p "$ToDelete"
$ ls /tmp/ToDelete/
$ destdir=~/FolderA
$ cd ~/FolderB
/FolderB$ find . -type f -exec cmp -s '{}' "$destdir/{}" \; -exec mv -v "$destdir/{}" "$ToDelete"/ \;
‘/home/Fischer/FolderA/./8.jpg’ -> ‘/tmp/ToDelete/8.jpg’
removed ‘/home/Fischer/FolderA/./8.jpg’
‘/home/Fischer/FolderA/./7.jpg’ -> ‘/tmp/ToDelete/7.jpg’
removed ‘/home/Fischer/FolderA/./7.jpg’
/FolderB$ cd ~/FolderC
/FolderC$ find . -type f -exec cmp -s '{}' "$destdir/{}" \; -exec mv -v "$destdir/{}" "$ToDelete"/ \;
‘/home/Fischer/FolderA/./6.jpg’ -> ‘/tmp/ToDelete/6.jpg’
removed ‘/home/Fischer/FolderA/./6.jpg’
/FolderC$ ls /tmp/ToDelete/
6.jpg 7.jpg 8.jpg
/FolderC$ ls -l ~/FolderA
1.jpg 2.jpg
/FolderC$ C00L ;)
And How it works?
When you switch into your FolderB or FolderC and you run find command, so you are looking for any file in it (.
refer to current directory) and then with cmp command(used to compare two files byte by byte) you compare each files({}
) in FolderB/FolderC with files in destdir
(FolderA($destdir/{}
)) if they are the same then we move that file(from FolderA to temp directory in /tmp/ToDelete
) with next mv command -exec mv "$destdir/{}" "$ToDelete"/ \;
.
The program findimagedupes should do what you request:
Finds visually similar or duplicate images
The program is a simple perl program and can be started from the command line - but is also available as a software package.
you could use the program fslint
it searches for duplicates (among other things)
fslint can be downloaded in the software center. fslint has a user interface when you open the program, the first tab is about finding duplicata. you can specify the folder/folders.
more information : user manual fslint
-
AU encourages high quality answers. Can you please elaborate how to use
fslint
to search for duplicates? Oct 24, 2014 at 1:22 -
fslint can be downloaded in the software center fslint has a user interface when you open the program, the first tab is about finding duplicata. you can specify the folder/folders.– vikingOct 24, 2014 at 9:18
if it's a small number of photos, you could use nautilus or another file manager
- go to the parent folder of A, B, C
- search for .jpg (or the file extension of your pictures: .png, .gif, ...)
- sort alphabetically (make sure to view the sourcepath of the file)
- delete the duplicate files you don't need anymore
There are many duplicate photo finder utilities available online. Some are better than others, some are faster, some are easy to use, many are free, and some have to pay to unlock full functionality.
Perform a Google search with the best duplicate photo finder phrases to figure out what's available and find the one that suits your needs.