~ubuntu-branches/ubuntu/utopic/coreutils/utopic-proposed

« back to all changes in this revision

Viewing changes to src/du.c

  • Committer: Colin Watson
  • Date: 2013-10-30 15:48:33 UTC
  • mfrom: (8.3.5 sid)
  • Revision ID: cjwatson@canonical.com-20131030154833-xdt6e1yfffqom1c4
merge from Debian 8.21-1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* du -- summarize disk usage
2
 
   Copyright (C) 1988-2012 Free Software Foundation, Inc.
 
2
   Copyright (C) 1988-2013 Free Software Foundation, Inc.
3
3
 
4
4
   This program is free software: you can redistribute it and/or modify
5
5
   it under the terms of the GNU General Public License as published by
147
147
   is at level 0, so 'du --max-depth=0' is equivalent to 'du -s'.  */
148
148
static size_t max_depth = SIZE_MAX;
149
149
 
 
150
/* Only output entries with at least this SIZE if positive,
 
151
   or at most if negative.  See --threshold option.  */
 
152
static intmax_t opt_threshold = 0;
 
153
 
150
154
/* Human-readable options for output.  */
151
155
static int human_output_opts;
152
156
 
218
222
  {"separate-dirs", no_argument, NULL, 'S'},
219
223
  {"summarize", no_argument, NULL, 's'},
220
224
  {"total", no_argument, NULL, 'c'},
 
225
  {"threshold", required_argument, NULL, 't'},
221
226
  {"time", optional_argument, NULL, TIME_OPTION},
222
227
  {"time-style", required_argument, NULL, TIME_STYLE_OPTION},
223
228
  {GETOPT_HELP_OPTION_DECL},
268
273
"), program_name, program_name);
269
274
      fputs (_("\
270
275
Summarize disk usage of each FILE, recursively for directories.\n\
271
 
\n\
272
 
"), stdout);
273
 
      fputs (_("\
274
 
Mandatory arguments to long options are mandatory for short options too.\n\
275
 
"), stdout);
276
 
      fputs (_("\
 
276
"), stdout);
 
277
 
 
278
      emit_mandatory_arg_note ();
 
279
 
 
280
      fputs (_("\
 
281
  -0, --null            end each output line with 0 byte rather than newline\n\
277
282
  -a, --all             write counts for all files, not just directories\n\
278
283
      --apparent-size   print apparent sizes, rather than disk usage; although\
279
284
\n\
289
294
  -c, --total           produce a grand total\n\
290
295
  -D, --dereference-args  dereference only symlinks that are listed on the\n\
291
296
                          command line\n\
 
297
  -d, --max-depth=N     print the total for a directory (or file, with --all)\n\
 
298
                          only if it is N or fewer levels below the command\n\
 
299
                          line argument;  --max-depth=0 is the same as\n\
 
300
                          --summarize\n\
292
301
"), stdout);
293
302
      fputs (_("\
294
303
      --files0-from=F   summarize disk usage of the NUL-terminated file\n\
297
306
  -H                    equivalent to --dereference-args (-D)\n\
298
307
  -h, --human-readable  print sizes in human readable format (e.g., 1K 234M 2G)\
299
308
\n\
300
 
      --si              like -h, but use powers of 1000 not 1024\n\
301
309
"), stdout);
302
310
      fputs (_("\
303
311
  -k                    like --block-size=1K\n\
 
312
  -L, --dereference     dereference all symbolic links\n\
304
313
  -l, --count-links     count sizes many times if hard linked\n\
305
314
  -m                    like --block-size=1M\n\
306
315
"), stdout);
307
316
      fputs (_("\
308
 
  -L, --dereference     dereference all symbolic links\n\
309
317
  -P, --no-dereference  don't follow any symbolic links (this is the default)\n\
310
 
  -0, --null            end each output line with 0 byte rather than newline\n\
311
318
  -S, --separate-dirs   do not include size of subdirectories\n\
 
319
      --si              like -h, but use powers of 1000 not 1024\n\
312
320
  -s, --summarize       display only a total for each argument\n\
313
321
"), stdout);
314
322
      fputs (_("\
315
 
  -x, --one-file-system    skip directories on different file systems\n\
316
 
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE\n\
317
 
      --exclude=PATTERN    exclude files that match PATTERN\n\
318
 
  -d, --max-depth=N     print the total for a directory (or file, with --all)\n\
319
 
                          only if it is N or fewer levels below the command\n\
320
 
                          line argument;  --max-depth=0 is the same as\n\
321
 
                          --summarize\n\
322
 
"), stdout);
323
 
      fputs (_("\
 
323
  -t, --threshold=SIZE  exclude entries smaller than SIZE if positive,\n\
 
324
                          or entries greater than SIZE if negative\n\
324
325
      --time            show time of the last modification of any file in the\n\
325
326
                          directory, or any of its subdirectories\n\
326
327
      --time=WORD       show time as WORD instead of modification time:\n\
329
330
                          full-iso, long-iso, iso, +FORMAT\n\
330
331
                          FORMAT is interpreted like 'date'\n\
331
332
"), stdout);
 
333
      fputs (_("\
 
334
  -X, --exclude-from=FILE  exclude files that match any pattern in FILE\n\
 
335
      --exclude=PATTERN    exclude files that match PATTERN\n\
 
336
  -x, --one-file-system    skip directories on different file systems\n\
 
337
"), stdout);
332
338
      fputs (HELP_OPTION_DESCRIPTION, stdout);
333
339
      fputs (VERSION_OPTION_DESCRIPTION, stdout);
334
340
      emit_blocksize_note ("DU");
579
585
  duinfo_add (&tot_dui, &dui);
580
586
 
581
587
  if ((IS_DIR_TYPE (info) && level <= max_depth)
582
 
      || ((opt_all && level <= max_depth) || level == 0))
583
 
    print_size (&dui_to_print, file);
 
588
      || (opt_all && level <= max_depth)
 
589
      || level == 0)
 
590
    {
 
591
      /* Print or elide this entry according to the --threshold option.  */
 
592
      if (opt_threshold < 0
 
593
          ? dui_to_print.size <= -opt_threshold
 
594
          : dui_to_print.size >= opt_threshold)
 
595
        print_size (&dui_to_print, file);
 
596
    }
584
597
 
585
598
  return ok;
586
599
}
703
716
  while (true)
704
717
    {
705
718
      int oi = -1;
706
 
      int c = getopt_long (argc, argv, "0abd:chHklmsxB:DLPSX:",
 
719
      int c = getopt_long (argc, argv, "0abd:chHklmst:xB:DLPSX:",
707
720
                           long_options, &oi);
708
721
      if (c == -1)
709
722
        break;
784
797
          opt_summarize_only = true;
785
798
          break;
786
799
 
 
800
        case 't':
 
801
          {
 
802
            enum strtol_error e;
 
803
            e = xstrtoimax (optarg, NULL, 0, &opt_threshold, "kKmMGTPEZY0");
 
804
            if (e != LONGINT_OK)
 
805
              xstrtol_fatal (e, oi, c, long_options, optarg);
 
806
            if (opt_threshold == 0 && *optarg == '-')
 
807
              {
 
808
                /* Do not allow -0, as this wouldn't make sense anyway.  */
 
809
                error (EXIT_FAILURE, 0, _("invalid --threshold argument '-0'"));
 
810
              }
 
811
          }
 
812
          break;
 
813
 
787
814
        case 'x':
788
815
          bit_flags |= FTS_XDEV;
789
816
          break;