Given a nested directory structure containing various files, I would like to find all the files within it, but where there are multiple files with the same name, I'd like to return just the largest file.
So, for example, given a directory structure like:
|--- foo.jpg (110 KB)
|--- bar.jpg (210 KB)
|--- dir
|----- foo.jpg (860 KB)
|----- baz.jpg (200 KB)
I'd like to produce the output lines (order unimportant):
bar.jpg
dir/foo.jpg
dir/baz.jpg
How can I do this, preferably from bash?
find -printf
to list all files, also printing their sizes, possibly splitting basename and dir, thensort
on the size, thensort
on the basename, and then see ifuniq
can look at single fields only or else useawk
, and then reassemble dirname and basename.