coreutils
[Top][All Lists]
Advanced

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

Re: [PATCH] Support for --min-size in du


From: Jakob Truelsen
Subject: Re: [PATCH] Support for --min-size in du
Date: Tue, 11 Oct 2011 21:00:50 +0200

On Tue, Oct 11, 2011 at 4:55 PM, Voelker, Bernhard
<address@hidden> wrote:
>
> Jakob Truelsen wrote:
>
>> On Tue, Oct 11, 2011 at 4:19 PM, Voelker, Bernhard
>> <address@hidden> wrote:
>> > Jakob Truelsen wrote:
>> >
>> >> I often find myself using sed to filter out only large entries in the
>> >> output of du, this patch adds a --min-size option to du to do this in
>> >> a more pratical way.
>> >>
>> >> commit 3ce873cddcd608a654750ffa67d070c1ce82b036
>> >> Author: Jakob Truelsen <address@hidden>
>> >> Date:   Tue Oct 11 15:28:26 2011 +0200
>> >>
>> >>     Add min-size option to du to only show information about large 
>> >> entities
>> >
>> > why not use e.g. find -size?
>>
>> Primarily because I also want folders with lots of medium sized files
>> to show up, I have not found a way to do this with find
>
> good point ... although you could use 'sort -h' for filtering, e.g.
>
>  du -ah | sort -hr | head -n 10
>
> Your --min-size option is not a bad thing, however, maybe it's worth
> turning it into --size as in 'find' so that people could also filter
> files/directories smaller than a certain size.
>
> Berny

That is a good idea, here is a revised patch implementing that

commit 07ff6682a842717b08d983a9150ba2c48adbd169
Author: Jakob Truelsen <address@hidden>
Date:   Tue Oct 11 15:28:26 2011 +0200

    Add size option to du to only show information about large or small entries

diff --git a/src/du.c b/src/du.c
index fba7f7d..576e76e 100644
--- a/src/du.c
+++ b/src/du.c
@@ -141,6 +141,9 @@ static bool opt_separate_dirs = false;
    is at level 0, so `du --max-depth=0' is equivalent to `du -s'.  */
 static size_t max_depth = SIZE_MAX;

+/* Only output entries with at least this size if positive, at most
if negative */
+static intmax_t size = 0;
+
 /* Human-readable options for output.  */
 static int human_output_opts;

@@ -187,7 +190,8 @@ enum
   HUMAN_SI_OPTION,
   FTS_DEBUG,
   TIME_OPTION,
-  TIME_STYLE_OPTION
+  TIME_STYLE_OPTION,
+  SIZE_OPTION
 };

 static struct option const long_options[] =
@@ -206,6 +210,7 @@ static struct option const long_options[] =
   {"human-readable", no_argument, NULL, 'h'},
   {"si", no_argument, NULL, HUMAN_SI_OPTION},
   {"max-depth", required_argument, NULL, 'd'},
+  {"size", required_argument, NULL, SIZE_OPTION},
   {"null", no_argument, NULL, '0'},
   {"no-dereference", no_argument, NULL, 'P'},
   {"one-file-system", no_argument, NULL, 'x'},
@@ -314,6 +319,10 @@ Mandatory arguments to long options are mandatory
for short options too.\n\
                           only if it is N or fewer levels below the command\n\
                           line argument;  --max-depth=0 is the same as\n\
                           --summarize\n\
+      --size=SIZE       if positive only output entries of size at
least SIZE.\n\
+                          If negative only output entries of size at
most SIZE.\n\
+                          Suffixes k, M and G may be used for
Kilobytes, Megabytes\n\
+                          and Gigabytes respectively.\n\
 "), stdout);
       fputs (_("\
       --time            show time of the last modification of any
file in the\n\
@@ -554,8 +563,9 @@ process_file (FTS *fts, FTSENT *ent)
      do let its size contribute to the total. */
   duinfo_add (&tot_dui, &dui);

-  if ((IS_DIR_TYPE (info) && level <= max_depth)
-      || ((opt_all && level <= max_depth) || level == 0))
+  if ( (size < 0?dui_to_print.size <= -size:dui_to_print.size >= size) &&
+       ((IS_DIR_TYPE (info) && level <= max_depth)
+       || ((opt_all && level <= max_depth) || level == 0)))
     print_size (&dui_to_print, file);

   return ok;
@@ -787,6 +797,15 @@ main (int argc, char **argv)
           time_style = optarg;
           break;

+        case SIZE_OPTION:
+          {
+           char *ptr;  
+            enum strtol_error e = xstrtoimax (optarg, &ptr, 0, &size,
"eEgGkKmMpPtTyYzZ0");
+            if (e != LONGINT_OK)
+              xstrtol_fatal (e, oi, c, long_options, optarg);
+          }
+          break;
+
         case_GETOPT_HELP_CHAR;

         case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);



reply via email to

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