bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Feature Request: du --dir-with-slash


From: Thomas Guettler
Subject: Re: Feature Request: du --dir-with-slash
Date: Mon, 10 Mar 2008 10:13:10 +0100
User-agent: Thunderbird 2.0.0.9 (X11/20070801)

Pádraig Brady schrieb:
> Thomas Guettler wrote:
>   
>> Hi,
>>
>> I use "du -ax / | sort -rn > /var/tmp/du-`date --iso`" to get the sorted
>> total size of all
>> files and directories.
>>
>> Unfortunately you can't see a difference between a directory and a file
>> in the output. It would be nice if the directories would be added by a
>> slash.
>>     
Thank you for being interested. I wrote a patch which makes the slash
optional:

src/du --help:
 ...
  -z, --dir-with-slash  append a slash to directories.

 Thomas

-- 
Thomas Güttler, http://www.tbz-pariv.de/ 
Bernsdorfer Str. 210-212, 09126 Chemnitz, Tel.: 0371/5347-917
TBZ-PARIV GmbH  Geschäftsführer: Dr. Reiner Wohlgemuth
Sitz der Gesellschaft: Chemnitz Registergericht: Chemnitz HRB 8543

--- src/du.c~   2007-11-25 14:23:31.000000000 +0100
+++ src/du.c    2008-03-10 10:12:35.206483708 +0100
@@ -139,6 +139,9 @@
 /* If true, output the NUL byte instead of a newline at the end of each line. 
*/
 static bool opt_nul_terminate_output = false;
 
+/* If true, output directories with a trailing slash */
+static bool opt_dir_with_slash = false;
+
 /* If true, print a grand total at the end.  */
 static bool print_grand_total = false;
 
@@ -216,6 +219,7 @@
   {"si", no_argument, NULL, HUMAN_SI_OPTION},
   {"max-depth", required_argument, NULL, MAX_DEPTH_OPTION},
   {"null", no_argument, NULL, '0'},
+  {"dir-with-slash", no_argument, NULL, 'z'},
   {"no-dereference", no_argument, NULL, 'P'},
   {"one-file-system", no_argument, NULL, 'x'},
   {"separate-dirs", no_argument, NULL, 'S'},
@@ -321,6 +325,9 @@
                           --summarize\n\
 "), stdout);
       fputs (_("\
+  -z, --dir-with-slash  append a slash to directories.\n\
+"), stdout);
+      fputs (_("\
       --time            show time of the last modification of any file in 
the\n\
                           directory, or any of its subdirectories\n\
       --time=WORD       show time as WORD instead of modification time:\n\
@@ -437,7 +444,7 @@
 /* Print size (and optionally time) indicated by *PDUI, followed by STRING.  */
 
 static void
-print_size (const struct duinfo *pdui, const char *string)
+print_size (const struct duinfo *pdui, const char *string, FTSENT *ent)
 {
   print_only_size (pdui->size);
   if (opt_time)
@@ -445,7 +452,10 @@
       putchar ('\t');
       show_date (time_format, pdui->tmax);
     }
-  printf ("\t%s%c", string, opt_nul_terminate_output ? '\0' : '\n');
+  printf ("\t%s%s%c", string, 
+          ent && opt_dir_with_slash && IS_DIR_TYPE(ent->fts_info) ? "/" : "",
+          opt_nul_terminate_output ? '\0' : '\n' 
+          );
   fflush (stdout);
 }
 
@@ -607,7 +617,7 @@
 
   if ((IS_DIR_TYPE (ent->fts_info) && level <= max_depth)
       || ((opt_all && level <= max_depth) || level == 0))
-    print_size (&dui_to_print, file);
+    print_size (&dui_to_print, file, ent);
 
   return ok;
 }
@@ -653,7 +663,7 @@
     }
 
   if (print_grand_total)
-    print_size (&tot_dui, _("total"));
+    print_size (&tot_dui, _("total"), NULL);
 
   return ok;
 }
@@ -697,7 +707,7 @@
   for (;;)
     {
       int oi = -1;
-      int c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:",
+      int c = getopt_long (argc, argv, DEBUG_OPT "0abchHklmsxB:DLPSX:z",
                           long_options, &oi);
       if (c == -1)
        break;
@@ -825,6 +835,10 @@
            }
          break;
 
+    case 'z':
+      opt_dir_with_slash = true;
+      break;
+
        case FILES0_FROM_OPTION:
          files_from = optarg;
          break;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]