I'm running Mac OSX and trying to use the command line to find the number of files I have with the same name. I tried to use the following command:find ~ -type f -name * -print | basename | sort | uniq -d > duplicate_filesIt doesn't work! When I do the following:find ~ -type f -name * -print > duplicate_filesThen duplicate_files does contain the paths of all my files. So I think the issue is with basename - it doesn't accept standard input. I then tried the following:basename $(find ~ -type f -name * -print) > duplicate_filesbut again that doesn't seem to work. Search on the internet doesn't seem to yield much joy. Any thoughts most welcome.
Use basename to parse a list of paths held in a file
find;osx;filenames;duplicate;basename
basename operates on its command line argument, it doesn't read from standard input.You don't need to call the basename utility, and you'd better not: all it would do is strip off the part before the last /, and it would be slow to call an external command for each entry, you can use a text processing utility instead.find ~ -type f | sed 's!.*/!!' | sort | uniq -dIt may be more useful to keep track of the location of the files. Sorting by name makes it easier to locate duplicates, but sort doesn't have an option to use the last field. What you can do is copy the last /-separated field to the beginning, then sort, and then use a bit of ad hoc awk processing to extract and present the duplicates.find ~ -type f |sed 's!.*/\(.*\)!\1/&!' |   # copy the last field to the beginningsort -t/ -k1,1 |cut -d/ -f2- |   # remove the extra first field (could be combined with awk below)awk -F / '{    if ($NF == name) {        if (previous != ) {print previous; previous = }        print    } else {        previous = $0        name = $NF    }'(Note that I assume that none of your file names contain newline characters.)