From 37eda0b07d63396a3fbbfa58f4b5390ae0f97ac5 Mon Sep 17 00:00:00 2001 From: scrappy Date: Wed, 23 Oct 1996 06:53:57 +0000 Subject: Add a 'depth (-d#)' flag to du patched (context diff), compiled (w/ -Wall) and tested Submitted by: John-Mark Gurney --- usr.bin/du/du.1 | 8 ++++++-- usr.bin/du/du.c | 33 ++++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 11 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/du/du.1 b/usr.bin/du/du.1 index fdea71f..59e9711 100644 --- a/usr.bin/du/du.1 +++ b/usr.bin/du/du.1 @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" @(#)du.1 8.2 (Berkeley) 4/1/94 -.\" $Id$ +.\" $Id: du.1,v 1.5 1996/08/29 18:05:49 wosch Exp $ .\" .Dd April 1, 1994 .Dt DU 1 @@ -41,7 +41,7 @@ .Sh SYNOPSIS .Nm du .Op Fl H | Fl L | Fl P -.Op Fl a | Fl s +.Op Fl a | s | d Ar depth .Op Fl x .Op Ar file ... .Sh DESCRIPTION @@ -68,6 +68,10 @@ All symbolic links are followed. No symbolic links are followed. .It Fl a Display an entry for each file in the file hierarchy. +.It Fl d Ar depth +Displays all directories only +.Ar depth +directories deep. .It Fl k Report in 1024-byte (1-Kbyte) blocks rather than the default. Note that this overrides the diff --git a/usr.bin/du/du.c b/usr.bin/du/du.c index 26747c8..47f797f 100644 --- a/usr.bin/du/du.c +++ b/usr.bin/du/du.c @@ -66,14 +66,15 @@ main(argc, argv) FTS *fts; FTSENT *p; long blocksize; - int ftsoptions, listdirs, listfiles; - int Hflag, Lflag, Pflag, aflag, ch, notused, rval, sflag; + int ftsoptions, listdirs, listfiles, depth; + int Hflag, Lflag, Pflag, aflag, ch, notused, rval, sflag, dflag; char **save; save = argv; - Hflag = Lflag = Pflag = aflag = sflag = 0; + Hflag = Lflag = Pflag = aflag = sflag = dflag = 0; + depth = INT_MAX; ftsoptions = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "HLPaksx")) != EOF) + while ((ch = getopt(argc, argv, "HLPad:ksx")) != EOF) switch (ch) { case 'H': Hflag = 1; @@ -99,6 +100,14 @@ main(argc, argv) case 'x': ftsoptions |= FTS_XDEV; break; + case 'd': + dflag = 1; + depth=atoi(optarg); + if(errno == ERANGE) { + (void)fprintf(stderr, "Invalid argument to option d: %s", optarg); + usage(); + } + break; case '?': default: usage(); @@ -126,12 +135,17 @@ main(argc, argv) } if (aflag) { - if (sflag) + if (sflag || dflag) usage(); listdirs = listfiles = 1; - } else if (sflag) + } else if (sflag) { + if (dflag) + usage(); listdirs = listfiles = 0; - else { + } else if (dflag) { + listfiles = 0; + listdirs = 1; + } else { listfiles = 0; listdirs = 1; } @@ -160,7 +174,8 @@ main(argc, argv) * or directories and this is post-order of the * root of a traversal, display the total. */ - if (listdirs || !listfiles && !p->fts_level) + if ((p->fts_level <= depth && listdirs) || + (!listfiles && !p->fts_level)) (void)printf("%ld\t%s\n", howmany(p->fts_number, blocksize), p->fts_path); @@ -227,6 +242,6 @@ usage() { (void)fprintf(stderr, - "usage: du [-H | -L | -P] [-a | -s] [-k] [-x] [file ...]\n"); + "usage: du [-H | -L | -P] [-a | -s | -d depth] [-k] [-x] [file ...]\n"); exit(1); } -- cgit v1.1