#!/bin/sh LASTBASE="" find $1 -type f -print | rev | sort | rev | while read FILE do BASE=$(basename "$FILE") if [ "$BASE" = "$LASTBASE" ]; then rm "$FILE" LASTBASE="$BASE" done
If you pipe the output of
Edit: So this method does break if filenames contain double (consecutive) spaces, because
|show 2 more comments|
I just found this "gem" in an old bash history and it, well, actually works without stumbling over whitespaces in filenames.
Removing is not implemented here because it might be hard to decide which version of the doubled files you want to keep.
If you just want to look at filenames and not at contents, it gets even easier:
Update: Unfortunately this version is breaking with whitespaces in filenames again.
|show 1 more comment|
The problem lies in this line of code