[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Support for --min-size in du
From: |
Jakob Truelsen |
Subject: |
[PATCH] Support for --min-size in du |
Date: |
Tue, 11 Oct 2011 15:35:13 +0200 |
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
diff --git a/src/du.c b/src/du.c
index fba7f7d..94d317e 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 atleast this size */
+static size_t min_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,
+ MIN_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'},
+ {"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'},
@@ -314,6 +319,7 @@ 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\
+ --min-size=SIZE only output entries with size at least SIZE\n\
"), stdout);
fputs (_("\
--time show time of the last modification of any
file in the\n\
@@ -554,8 +560,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 (dui_to_print.size >= min_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 +794,15 @@ main (int argc, char **argv)
time_style = optarg;
break;
+ case MIN_SIZE_OPTION:
+ {
+ char *ptr;
+ enum strtol_error e = xstrtoumax (optarg, &ptr, 0,
&min_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);
- [PATCH] Support for --min-size in du,
Jakob Truelsen <=