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.
Ubuntu – Search for duplicate photos
deleteduplicate filesperlsearch
Related Solutions
FSlint is a versatile duplicate finder that includes a function for finding duplicate names:
The FSlint package for Ubuntu emphasizes the graphical interface, but as is explained in the FSlint FAQ a command-line interface is available via the programs in /usr/share/fslint/fslint/
. Use the --help
option for documentation, e.g.:
$ /usr/share/fslint/fslint/fslint --help
File system lint.
A collection of utilities to find lint on a filesystem.
To get more info on each utility run 'util --help'.
findup -- find DUPlicate files
findnl -- find Name Lint (problems with filenames)
findu8 -- find filenames with invalid utf8 encoding
findbl -- find Bad Links (various problems with symlinks)
findsn -- find Same Name (problems with clashing names)
finded -- find Empty Directories
findid -- find files with dead user IDs
findns -- find Non Stripped executables
findrs -- find Redundant Whitespace in files
findtf -- find Temporary Files
findul -- find possibly Unused Libraries
zipdir -- Reclaim wasted space in ext2 directory entries
$ /usr/share/fslint/fslint/findsn --help
find (files) with duplicate or conflicting names.
Usage: findsn [-A -c -C] [[-r] [-f] paths(s) ...]
If no arguments are supplied the $PATH is searched for any redundant
or conflicting files.
-A reports all aliases (soft and hard links) to files.
If no path(s) specified then the $PATH is searched.
If only path(s) specified then they are checked for duplicate named
files. You can qualify this with -C to ignore case in this search.
Qualifying with -c is more restictive as only files (or directories)
in the same directory whose names differ only in case are reported.
I.E. -c will flag files & directories that will conflict if transfered
to a case insensitive file system. Note if -c or -C specified and
no path(s) specifed the current directory is assumed.
Example usage:
$ /usr/share/fslint/fslint/findsn /usr/share/icons/ > icons-with-duplicate-names.txt
$ head icons-with-duplicate-names.txt
-rw-r--r-- 1 root root 683 2011-04-15 10:31 Humanity-Dark/AUTHORS
-rw-r--r-- 1 root root 683 2011-04-15 10:31 Humanity/AUTHORS
-rw-r--r-- 1 root root 17992 2011-04-15 10:31 Humanity-Dark/COPYING
-rw-r--r-- 1 root root 17992 2011-04-15 10:31 Humanity/COPYING
-rw-r--r-- 1 root root 4776 2011-03-29 08:57 Faenza/apps/16/DC++.xpm
-rw-r--r-- 1 root root 3816 2011-03-29 08:57 Faenza/apps/22/DC++.xpm
-rw-r--r-- 1 root root 4008 2011-03-29 08:57 Faenza/apps/24/DC++.xpm
-rw-r--r-- 1 root root 4456 2011-03-29 08:57 Faenza/apps/32/DC++.xpm
-rw-r--r-- 1 root root 7336 2011-03-29 08:57 Faenza/apps/48/DC++.xpm
-rw-r--r-- 1 root root 918 2011-03-29 09:03 Faenza/apps/16/Thunar.png
Best Answer
Try this command:
How to use?
Step 1: Make a temporary directory to moving duplicate files into that:
Step 2: Set
destdir
to your FolderA directory which we want to delete duplicate photos from there.Step 3 cd to your first source directory(FolderB) and run the command
Step 4: Now cd to your next source directory(FolderC) and run again the command
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:
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 indestdir
(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"/ \;
.