# Delimiting file sizes by thousands in ls -l listings



## MMacD (Jul 16, 2017)

For the sake of avoiding eyestrain, I'm trying to modify my ls(1) alias such that listings will have the file sizes delimited in thousands..

Supposedly, the -, switch will do the job, but only if thousands_sep is defined in the locale.

I followed the instructions for setting up locale values in /etc/login.conf, where thousands_sep was listed but undefined.  First I tried a literal comma and when that didn't work, the ascii value (0x2C).   I remembered to call `cap_mkdb /etc/login.conf` both times, and rebooted, but  I'm still not getting the separators. 

Is there some magic I still need to do?


----------



## mrclksr (Jul 16, 2017)

Hi MMacD,

You don't have to set thousands_sep yourself. Setting LC_ALL=en_US.UTF-8 should do the job. I don't know why, but if you omit the character set, thousands_sep is undefined.


----------



## poorandunlucky (Jul 16, 2017)

I use `ls -alh` sometimes. If you do `ls -alh | more`, the list will be paginated if it's longer than the buffer.  (more quits at eof whereas less doesn't).

... just sayin'.


----------



## MMacD (Jul 17, 2017)

mrclksr said:


> Hi MMacD,
> 
> You don't have to set thousands_sep yourself. Setting LC_ALL=en_US.UTF-8 should do the job. I don't know why, but if you omit the character set, thousands_sep is undefined.



I just tried setting first LANG and then LC_ALL.  I set them first to en_US.ISO8859-1 and then, in desperation, to en_US.UTF-8.  None of them caused `ls -,` to delimit file sizes


----------



## mrclksr (Jul 17, 2017)

Is thousands_sep defined if you set LC_ALL to en_US.ISO8859-1?

`LC_ALL=en_US.ISO8859-1 locale -k | grep ^thousands_sep`


----------



## MMacD (Jul 17, 2017)

mrclksr said:


> Is thousands_sep defined if you set LC_ALL to en_US.ISO8859-1?
> 
> `LC_ALL=en_US.ISO8859-1 locale -k | grep ^thousands_sep`



Nope!  It turns out that it's not.  And apparently following the instructions for setting it in login.conf didn't work as advertised either.

But I just finished brute-forcing a solution:  I went to /usr/src/bin/ls and permanently set 
	
	



```
f_thousands
```
(the var that maps the switch) to 1.  Called `make`, renamed /bin/ls to /bin/ls.old, and copied /usr/src/bin/ls to /bin/.  Basta!


----------



## mrclksr (Jul 17, 2017)

MMacD said:


> Nope! It turns out that it's not. And apparently following the instructions for setting it in login.conf didn't work as advertised either.



That's odd.



MMacD said:


> But I just finished brute-forcing a solution:  I went to /usr/src/bin/ls and permanently set
> 
> 
> 
> ...



That's a quite pragmatic approach


----------



## MMacD (Jul 17, 2017)

I haven't written anything in C under Unix in so many years that I've almost completely forgotten how.  But now that I've done that trivial wee fixie, I do believe I'll go add another switch to tell `ls` to list directories first.  

The original Unix principle of chaining together scraps of code that each do one thing has always been honored much more in the breach than the keeping.  Trying to force `ls` to list dirs first is ridiculously difficult and obnoxious, and generally  doesn't even work.  So making it switch-selectable should be nice.


----------



## MMacD (Jul 17, 2017)

mrclksr said:


> That's a quite pragmatic approach



We Scots are noted for our pragmatism.  

It made some sense not to spend space for delimiters when lines were only 80 chars at most and file sizes were small, but that's not been the case for some years now.  Nearly 30, actually, by my reckoning.  Delimiting should have been made the default long since.


----------



## mrclksr (Jul 17, 2017)

MMacD said:


> I haven't written anything in C under Unix in so many years that I've almost completely forgotten how.  But now that I've done that trivial wee fixie, I do believe I'll go add another switch to tell `ls` to list directories first.



It seems to be a good educational project. Have fun!


----------



## gfx (Jul 19, 2017)

Just realized i've been content with the `ll -k` output until i've seen this thread. AWK one-liner to the rescue:


```
ll -k | awk '{ for (i=1; i <= NF; i++) if (i==5) { printf FS "%\047d", $i } else { printf FS $i } print NL }'
```

The output formatting can be improved though.


----------

