wc -l * gives me the number of lines in each file in the directory but does not sort them. ls -l -S sorts by the number of bytes. How to I get the files sorted by the number of lines. Thanks
Thanks that worked. I looked at the man pages for sort. The explanation for -n (compare according to string numerical value) isn't clear. What is the string numerical value?
Sorting strings that contain numbers might not get the result you expect because sorting numeric strings of differing lengths in lexical order don't come out the same as numeric order. Length is irrelevant in lexical order but matters in numeric order.
Thanks that worked. I looked at the man pages for sort. The explanation for -n (compare according to string numerical value) isn't clear. What is the string numerical value?
-n Restrict the sort key to an initial numeric string, consisting of optional
<blank> characters, optional minus-sign, and zero or more digits with an
optional radix character and thousands separators (as defined in the current
locale), which shall be sorted by arithmetic value. An empty digit string shall
be treated as zero. Leading zeros and signs on zeros shall not affect ordering.
-r Reverse the sense of comparisons.
So it's treated as a leading number, possibly with non-numeric content afterwards.
I often use "sort -nr" to get a reverse sort, largest first.
Fortuitously, wc aligns its numeric output on the decimal point, so -n isn't even needed. However, not all utilities do, so it's safer to get into the habit of using -n whenever you want to sort in numeric order.