need search through sub folders of current folder recursively , list files of type , number of duplicates
e.g. if current folder home , there 2 sub folders dir1 , dir2 need search dir1 , dir2 , list file names , number of duplicates
this have far: using
find -name "*.h" . to list of files of type. need count duplicates , create new list like
file1.h 2 file2.h 1 where file1 file name , 2 number of duplicates overall.
use uniq --count
you can use set of core utilities quickly. example, given following setup:
mkdir -p foo/{bar,baz} touch foo/bar/file{1,2}.h touch foo/baz/file{2,3}.h you can find (and count) files pipeline this:
find foo -name \*.h -print0 | xargs -0n1 basename | sort | uniq -c this results in following output:
1 file1.h 2 file2.h 1 file3.h if want other output formats, or order list in other way alphabetically file, can extend pipeline sort (e.g. sort -nr) or reformat columns sed, awk, perl, ruby, or text-munging language of choice.
Comments
Post a Comment