This solution writes one temporary file to a temporary directory for each unique file name. In the temporary file, I write the path where I first found a unique file name, so that I can output it later. So, I create a lot more files that are other hosted solutions. But I realized that.
Below is a script called fndupe .
#!/bin/bash # Create a temp directory to contain placeholder files. tmp_dir=`mktemp -d` # Get paths of files to test from standard input. while read p; do fname=$(basename "$p") tmp_path=$tmp_dir/$fname if [[ -e $tmp_path ]]; then q=`cat "$tmp_path"` echo "duplicate: $p" echo " first: $q" else echo $p > "$tmp_path" fi done exit
The following is an example of using a script.
$ find . -name '*.tif' | fndupe
The following is sample output when the script finds duplicate file names.
duplicate: a/b/extra/gobble.tif first: a/b/gobble.tif
Tested with Bash version: GNU bash, version 4.1.2(1)-release (x86_64-redhat-linux-gnu)
source share