How to find the largest as in total size (by length) header file (.h) in the /usr directory ?
To search in subdirectories too.
I did this as follows:
find . - name *.h | xargs awk | sort -n | less .
But this only outputs all files with the extension .h and their dimensions
2
Answers
Something like
(assuming none of the files have newlines in their names, of course)
or if you have GNU datamash available:
With GNU find, the
-printf
command lets you print lots of information about a file, including its size in bytes (%s
) and its name (%p
). Finding the max from that is easy.With GNU tools:
This allows filenames with newlines,
find
outputs a NUL terminated string and the following commands use NUL as delimiter instead of a newline. At the end of the pipeline,tr
converts the delimiter back to a newline.If you only want the filename, add
cut
to remove the first space separated field: