List all files with the same name and number of that files

filenames

I wonder if there is an easy command to list all files with the same names and number of that files? I would like to do it recursively and I do not mean concrete filename. I can imagine the output would look like this:

FILENAME   NUMBER
filename1    2
filename2    4
filename3    8 

Best Answer

Using GNU find:

find /some/path -type f -printf '%f\n' | sort | uniq -c

Using POSIX find:

find /some/path -type f | sed 's~^.*/~~' | sort | uniq -c

This assumes your filenames don't contain newlines.

Related Question