Question

I wanted to display the result of ls -C in my OpenGL application, but the output is columnized with tab characters instead of space characters. I could probably find the correct value by trial and error, but the question is where the ls gets this number or how does it calculate it?

ls / -C

bin   g\t\t      lib     lost+found  proc\tselinux  usr\tvmlinuz
boot  home\t      lib32   media\t  root\tsrv\t v\twin7
dev   initrd.img      lib64   mnt\t  run\tsys\t var\tx
etc   initrd.img.old  libx32  opt\t  sbin\ttmp
Was it helpful?

Solution

FreeBSD: /usr/src/bin/ls/print.c

tabwidth = 8;

As far as I can see, this value can't be changed, and is fixed.

GNU coreutils src/ls.c

tabsize = 8;

The tabsize can be set using the TABSIZE environment variable, or the -T / --tabsize option.

A tabsize of 8 is pretty standard with UNIX commandline utilities, but as far as I can find, this isn't standardized in POSIX.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top