Hello,

Please excuse me if I'm not going about this the right way but I would
like to offer a tiny patch for "ls" that adds an option to turn on digit
grouping for file sizes in the long output format.

(The support for displaying digit grouping is already present, all that
is required is an option for turning it on.)

I find it a very nice way to view file sizes because it makes it easy to
read the size of large files (like -h) but it does not hide any
information (unlike -h).

For example:

$ ls -l bigfile
-rw-r--r-- 1 samb samb 2146034154 2010-06-08 14:55 big.log

$ ls -ly bigfile
-rw-r--r-- 1 samb samb 2,146,034,154 2010-06-08 14:55 big.log

(The patch is against the latest git checkout but I have only actually
compiled it against the latest .tar release due to dependencies.)

Peace out,
Sam Bobroff.
diff --git a/src/ls.c b/src/ls.c
index 9549130..e5b772f 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -836,6 +836,7 @@ static struct option const long_options[] =
   {"block-size", required_argument, NULL, BLOCK_SIZE_OPTION},
   {"context", no_argument, 0, 'Z'},
   {"author", no_argument, NULL, AUTHOR_OPTION},
+  {"digit-group", no_argument, NULL, 'y'},
   {GETOPT_HELP_OPTION_DECL},
   {GETOPT_VERSION_OPTION_DECL},
   {NULL, 0, NULL, 0}
@@ -1639,7 +1640,7 @@ decode_switches (int argc, char **argv)
     {
       int oi = -1;
       int c = getopt_long (argc, argv,
-                           "abcdfghiklmnopqrstuvw:xABCDFGHI:LNQRST:UXZ1",
+                           "abcdfghiklmnopqrstuvw:xyABCDFGHI:LNQRST:UXZ1",
                            long_options, &oi);
       if (c == -1)
         break;
@@ -1760,6 +1761,10 @@ decode_switches (int argc, char **argv)
           format = horizontal;
           break;
 
+        case 'y':
+          human_output_opts = human_group_digits;
+          break;
+
         case 'A':
           if (ignore_mode == IGNORE_DEFAULT)
             ignore_mode = IGNORE_DOT_AND_DOTDOT;
@@ -4708,6 +4713,8 @@ Mandatory arguments to long options are mandatory for 
short options too.\n\
   -w, --width=COLS           assume screen width instead of current value\n\
   -x                         list entries by lines instead of by columns\n\
   -X                         sort alphabetically by entry extension\n\
+  -y, --digit-group          with -l, group digits of file size\n\
+
   -Z, --context              print any SELinux security context of each file\n\
   -1                         list one file per line\n\
 "), stdout);

Reply via email to