bug-coreutils
[Top][All Lists]
Advanced

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

--min-size option for du (patch)


From: Paul Chambers
Subject: --min-size option for du (patch)
Date: Wed, 14 Jan 2009 14:54:27 -0800
User-agent: Thunderbird 2.0.0.19 (Windows/20081209)

I'd like to submit the attached small patch for du. it adds a '--min-size' option, which can be used to filter the output to only include items of that size or greater.

I find it useful in locating large folders on disk in one pass, to zero in on the worst offenders when disk space is getting low.

regards,

-- Paul
diff -ru coreutils-6.12/man/du.1 coreutils-6.12p/man/du.1
--- coreutils-6.12/man/du.1     2008-05-31 14:26:01.000000000 -0700
+++ coreutils-6.12p/man/du.1    2008-11-09 09:50:24.000000000 -0800
@@ -1,5 +1,5 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.35.
-.TH DU "1" "May 2008" "GNU coreutils 6.12" "User Commands"
+.TH DU "1" "November 2008" "GNU coreutils 6.12" "User Commands"
 .SH NAME
 du \- estimate file space usage
 .SH SYNOPSIS
@@ -90,6 +90,10 @@
 line argument;  \fB\-\-max\-depth\fR=\fI0\fR is the same as
 \fB\-\-summarize\fR
 .TP
+\fB\-\-min\-size\fR=\fISIZE\fR
+Only print the total for a directory (or file, with
+\fB\-\-all\fR) if it is equal to or greater than this value.
+.TP
 \fB\-\-time\fR
 show time of the last modification of any file in the
 directory, or any of its subdirectories
diff -ru coreutils-6.12/src/du.c coreutils-6.12p/src/du.c
--- coreutils-6.12/src/du.c     2008-05-27 23:29:58.000000000 -0700
+++ coreutils-6.12p/src/du.c    2008-11-09 09:50:18.000000000 -0800
@@ -153,6 +153,10 @@
    is at level 0, so `du --max-depth=0' is equivalent to `du -s'.  */
 static size_t max_depth = SIZE_MAX;
 
+/* Only show the total for each directory (and file if --all) if it is
+       equal to or greater than this value.  */
+static uintmax_t min_size = 0;
+
 /* Human-readable options for output.  */
 static int human_output_opts;
 
@@ -198,6 +202,7 @@
   FILES0_FROM_OPTION,
   HUMAN_SI_OPTION,
   MAX_DEPTH_OPTION,
+  MIN_SIZE_OPTION,
   MEGABYTES_LONG_OPTION,
   TIME_OPTION,
   TIME_STYLE_OPTION
@@ -218,6 +223,7 @@
   {"human-readable", no_argument, NULL, 'h'},
   {"si", no_argument, NULL, HUMAN_SI_OPTION},
   {"max-depth", required_argument, NULL, MAX_DEPTH_OPTION},
+  {"min-size", required_argument, NULL, MIN_SIZE_OPTION},
   {"null", no_argument, NULL, '0'},
   {"no-dereference", no_argument, NULL, 'P'},
   {"one-file-system", no_argument, NULL, 'x'},
@@ -322,6 +328,8 @@
                           only if it is N or fewer levels below the command\n\
                           line argument;  --max-depth=0 is the same as\n\
                           --summarize\n\
+      --min-size=SIZE   Only print the total for a directory (or file, with\n\
+                          --all) if it is equal to or greater than this 
value.\n\
 "), stdout);
       fputs (_("\
       --time            show time of the last modification of any file in 
the\n\
@@ -608,8 +616,9 @@
   if (!print)
     return ok;
 
-  if ((IS_DIR_TYPE (ent->fts_info) && level <= max_depth)
-      || ((opt_all && level <= max_depth) || level == 0))
+  if ((IS_DIR_TYPE (ent->fts_info) || opt_all)
+      && (level <= max_depth || level == 0)
+         && (dui_to_print.size >= min_size))
     print_size (&dui_to_print, file);
 
   return ok;
@@ -773,6 +782,15 @@
          }
          break;
 
+       case MIN_SIZE_OPTION:           /* --min-size=SIZE */
+         {
+               enum strtol_error e = xstrtoumax (optarg, NULL, 0, &min_size,
+                                      "eEgGkKmMpPtTyYzZ0");
+               if (e != LONGINT_OK)
+             xstrtol_fatal (e, oi, c, long_options, optarg);
+      }
+         break;
+
        case MEGABYTES_LONG_OPTION:
          error (0, 0,
                 _("the --megabytes option is deprecated; use -m instead"));

reply via email to

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