Another quick hack which changes the output of ls, to make it display filesizes more readable.
ls can be found in the fileutils, my patch is against version 4.0.
The output of the standard ls with option -l looks like this:
-r--r--r-- 1 root root 1924022 Feb 9 18:08 Contents-i386.gz
So how large is the file? Is it 19 megs, or 1.9 megs or just 190 k? It is quite hard to tell for me on the first look, so I decided to change the ls output.
The new -M option together with -l now prints filesizes like this:
-r--r--r-- 1 root root 1_924_022 Feb 9 18:08 Contents-i386.gz
A lot nicer IMHO :)
Here's the diff:
--- ls.c.orig Mon Jul 19 23:24:25 1999
+++ ls.c Sun Apr 2 04:02:22 2000
@@ -36,6 +36,11 @@
Flaherty based on original patches by
Greg Lee . */
+/* modified on Apr 17 1999 by weasel
+ Peter Palfrader
+
+ with -M filesizes are now print like 1_234_567 to make life easier */
+
#ifdef _AIX
#pragma alloca
#endif
@@ -420,6 +425,12 @@
/* Nonzero means when a directory is found, display info on its
contents. -R */
+/* weasel add on Apr 17 1999 */
+static int easy_to_read_file_length;
+/* Nonzero means that file length is outputted more readable with
+ an underscore every 3 chars. -M */
+/* end of addition */
+
static int trace_dirs;
/* Nonzero means when an argument is a directory name, display info
@@ -699,6 +710,9 @@
(ls_mode == LS_LS ? "ls"
: (ls_mode == LS_MULTI_COL ? "dir" : "vdir")),
GNU_PACKAGE, VERSION);
+ /* weasel add on Apr 17 1999 */
+ printf ("\nmodified by Weasel (Peter Palfrader) \n -M added. this prints filesizes a more readable way.\n");
+ /* end of addition */
close_stdout ();
exit (EXIT_SUCCESS);
}
@@ -850,6 +864,7 @@
indicator_style = none;
print_inode = 0;
trace_links = 0;
+ easy_to_read_file_length = 0;
trace_dirs = 0;
immediate_dirs = 0;
all_files = 0;
@@ -905,8 +920,9 @@
}
}
+/*weasel changed on Apr 17 1999 -- added M*/
while ((c = getopt_long (argc, argv,
- "abcdefghiklmnopqrstuvw:xABCDFGHI:LNQRST:UX1",
+ "abcdefghiklmnopqrstuvw:xABCDFGHI:LMNQRST:UX1",
long_options, NULL)) != -1)
{
switch (c)
@@ -1060,6 +1076,12 @@
set_quoting_style (NULL, literal_quoting_style);
break;
+/*weasel added on Apr 17 1999*/
+ case 'M':
+ easy_to_read_file_length=1;
+ break;
+/*end of addition*/
+
case 'Q':
set_quoting_style (NULL, c_quoting_style);
break;
@@ -2280,10 +2302,71 @@
(unsigned) minor (f->stat.st_rdev));
else
{
- char hbuf[LONGEST_HUMAN_READABLE + 1];
- sprintf (p, "%8s ",
- human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
- output_block_size < 0 ? output_block_size : 1));
+ /* weasel modification on Apr 17 1999.
+ original code:
+
+ char hbuf[LONGEST_HUMAN_READABLE + 1];
+ sprintf (p, "%8s ",
+ human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
+ output_block_size < 0 ? output_block_size : 1));
+ */
+ if (!easy_to_read_file_length)
+ {
+ char hbuf[LONGEST_HUMAN_READABLE + 1];
+ sprintf (p, "%8s ",
+ human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
+ output_block_size < 0 ? output_block_size : 1));
+ }
+ else
+ {
+ /* a Quick and dirty implementation of i2a */
+ char hbuf[14]; /* hope that's long enough */
+ long size = f->stat.st_size;
+
+ int index;
+ int indexerror = 0;
+
+ for (index=0; index<13; index++)
+ {
+ hbuf[index] = ' ';
+ };
+ hbuf[13] = '\0';
+
+ index = 12;
+
+ if (!size)
+ {
+ hbuf[index] = '0';
+ }
+ else
+ {
+ int digits_to_underscore = 3;
+ while ((size) && (!indexerror))
+ {
+ if (!(digits_to_underscore--))
+ {
+ if (index>=0) { hbuf[index--] = '_'; }
+ else { indexerror = 1; };
+ digits_to_underscore = 2;
+ };
+ if (index>=0) { hbuf[index--] = 48 + (size % 10); }
+ else { indexerror = 1; };
+ size = size / 10;
+ };
+ };
+ if (!indexerror)
+ {
+ sprintf (p, "%s ", hbuf);
+ }
+ else
+ { /* do the original thing. this has been tested and looked at a 1000 times */
+ char hbuf[LONGEST_HUMAN_READABLE + 1];
+ sprintf (p, "%8s ",
+ human_readable ((uintmax_t) f->stat.st_size, hbuf, 1,
+ output_block_size < 0 ? output_block_size : 1));
+ };
+ };
+ /* end of modification */
}
p += strlen (p);
Changes distributed under the GPL.