bin/63547: Just a suggestion for the output of the 'ls -lah' command

Heiko Braun bsd at heiko-braun.de
Sun Feb 29 11:50:13 PST 2004


>Number:         63547
>Category:       bin
>Synopsis:       Just a suggestion for the output of the 'ls -lah' command
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Feb 29 11:50:13 PST 2004
>Closed-Date:
>Last-Modified:
>Originator:     Heiko Braun
>Release:        5.2-RELEASE
>Organization:
>Environment:
FreeBSD HEIKO-PC 5.2-RELEASE FreeBSD 5.2-RELEASE #0: Sun Jan 11 04:21:45 GMT 2004     root at wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC  i386
>Description:
I'd like to make some suggestion concerning the appearing of the
output of the "ls" command.
In detail, the output of "ls -lah" concerning the "-h" flag and the
size of the file displayed.

First, the list is not always column-aligned.
(sorry, can't express better what I mean, see example below).
And second, I don't think that a floating point output of files smaller
than 10 Bytes makes sense.

original ls -lah:
drwxr-xr-x   2 heiko  heiko  512B 29 Feb 20:11 .
drwxr-xr-x  36 heiko  heiko  4,0K 29 Feb 19:26 ..
-rw-r--r--   1 heiko  heiko    0B 29 Feb 20:08 file_with_0_byte
-rw-r--r--   1 heiko  heiko  977K 29 Feb 20:11 file_with_1000000_byte
-rw-r--r--   1 heiko  heiko  1000B 29 Feb 20:09 file_with_1000_byte
-rw-r--r--   1 heiko  heiko  100B 29 Feb 20:08 file_with_100_byte
-rw-r--r--   1 heiko  heiko  1000K 29 Feb 20:11 file_with_1024000_byte
-rw-r--r--   1 heiko  heiko  10,0B 29 Feb 20:08 file_with_10_byte
-rw-r--r--   1 heiko  heiko  1,0B 29 Feb 20:08 file_with_1_byte
-rw-r--r--   1 heiko  heiko  1,9M 29 Feb 20:11 file_with_2000000_byte
-rw-r--r--   1 heiko  heiko  2,0K 29 Feb 20:09 file_with_2000_byte

Changed one:
-rw-r--r--   1 heiko  heiko     0B 29 Feb 20:08 file_with_0_byte
-rw-r--r--   1 heiko  heiko   977K 29 Feb 20:11 file_with_1000000_byte
-rw-r--r--   1 heiko  heiko  1000B 29 Feb 20:09 file_with_1000_byte
-rw-r--r--   1 heiko  heiko   100B 29 Feb 20:08 file_with_100_byte
-rw-r--r--   1 heiko  heiko  1000K 29 Feb 20:11 file_with_1024000_byte
-rw-r--r--   1 heiko  heiko    10B 29 Feb 20:08 file_with_10_byte
-rw-r--r--   1 heiko  heiko     1B 29 Feb 20:08 file_with_1_byte
-rw-r--r--   1 heiko  heiko   1,9M 29 Feb 20:11 file_with_2000000_byte
-rw-r--r--   1 heiko  heiko   2,0K 29 Feb 20:09 file_with_2000_byte
>How-To-Repeat:
Type 'ls -lah' in a directory with files which size is displayed with a 4 digit number and/or file size is below 10 bytes.
>Fix:
I'd suggest to change the code in /usr/src/bin/ls/print.c in
function "printsize" the lines 626-630 from:
		if (dbytes == 0)
			(void)printf("%*s ", 4, "0B");
		else
			(void)printf("%*.*f%c ", 3,
			    dbytes > 10 ? 0 : 1, dbytes, "BKMGTPE"[unit]);

to:
		if (unit == 0)
			(void)printf("%*d%c ", 4, (int)dbytes, 'B');
		else
			(void)printf("%*.*f%c ", 4,
			    dbytes > 10 ? 0 : 1, dbytes, "BKMGTPE"[unit]);
>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list