I'm looking for a way to list all files in a directory, with both their size, and a line count. Right now I'm using stat -c \"%s %n\" /directory/*
to get file names and sizes, and I know I can use find /directory/ -type f -exec wc -l {} +
to get file name and line count, but is there any way I can get both at the same time?
Linux – get file size and line count at the same time
linuxlsstatwc
Best Answer
You are almost there.
will get file name, line count, and character count.
Strictly speaking,
-c
(a.k.a.--bytes
) is documented as counting bytes, which is probably what you want. There is also a-m
(a.k.a.--chars
) option for counting “characters”. From the choice of them
option letter, I guess this counts multi-byte characters; e.g., Unicode characters. There is also a-w
option for actually counting words.