canor421
canor421

Reputation: 11

how to find largest and smallest .c files in directory

I'm trying to find the size of the largest and smallest .c files in the linux kernel fs directory.

Here's what I have:

find . -type f -name '*.c' | du -ah | sort -nr | head -10

That just gives me a list of the 10 largest files in the directory, but not the largest .c files. Trying to use -regex '*.c' doesn't work either. Skipping du -ah doesn't list any files. Getting rid of head -10 and just looking at all the names it gives me, it seems like it's only returning directories and files named Kconfig and Makefile, but I thought find -type f was supposed to only give me files.

Any insight would be appreciated.

Upvotes: 1

Views: 143

Answers (1)

joeljpa
joeljpa

Reputation: 539

You were quite close, you forgot to use xargs before invoking du.

find . -type f -name '*.c' | xargs du -ah | sort -nr | head -10

For the smallest files, remove the reverse argument -r for sort.

find . -type f -name '*.c' | xargs du -ah | sort -n | head -10

xargs:

build and execute command lines from standard input

Upvotes: 0

Related Questions