This is a discussion on -d support for du within the mailing.openbsd.tech forums, part of the OpenBSD category; --> Hi, The enclosed modifications allow du to support the -d option to specify a maximum depth, and includes a ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, The enclosed modifications allow du to support the -d option to specify a maximum depth, and includes a corresponding change to the documentation. The -d option is present in FreeBSD's du. GNU du has similar functionality provided by --max-depth. David --- /usr/src/usr.bin/du/du.1 Sun Apr 17 13:27:23 2005 +++ du/du.1 Fri Aug 11 14:27:22 2006 @@ -61,6 +61,8 @@ The options are as follows: Display an entry for each file in the file hierarchy. ..It Fl c Display the grand total after all the arguments have been processed. +.It Fl d Ar depth +Display an entry for all files and directories up to the specified depth. ..It Fl H Symbolic links on the command line are followed. (Symbolic links encountered in the tree traversal are not followed.) diff -uNp /usr/src/usr.bin/du/du.c du/du.c --- /usr/src/usr.bin/du/du.c Wed Jan 25 06:20:03 2006 +++ du/du.c Fri Aug 11 14:53:05 2006 @@ -75,6 +75,8 @@ main(int argc, char *argv[]) quad_t totalblocks; int ftsoptions, listdirs, listfiles; int Hflag, Lflag, aflag, cflag, hflag, kflag, sflag; + unsigned int maxdepth = -1; + extern char *optarg; int ch, notused, rval; char **save; @@ -82,7 +84,7 @@ main(int argc, char *argv[]) Hflag = Lflag = aflag = cflag = hflag = kflag = sflag = 0; totalblocks = 0; ftsoptions = FTS_PHYSICAL; - while ((ch = getopt(argc, argv, "HLPachksxr")) != -1) + while ((ch = getopt(argc, argv, "HLPachksxrd:")) != -1) switch (ch) { case 'H': Hflag = 1; @@ -115,6 +117,9 @@ main(int argc, char *argv[]) case 'x': ftsoptions |= FTS_XDEV; break; + case 'd': + maxdepth = (int)strtol(optarg, (char**)NULL, 10); + break; case '?': default: usage(); @@ -183,9 +188,14 @@ main(int argc, char *argv[]) * or directories and this is post-order of the * root of a traversal, display the total. */ - if (listdirs || (!listfiles && !p->fts_level)) - prtout((quad_t)howmany(p->fts_number, blocksize), - p->fts_path, hflag); + if (listdirs || (!listfiles && !p->fts_level)) + /* + * If a maximum depth is specified do not display + * any directories deeper than the specified depth + */ + if (p->fts_level <= maxdepth) + prtout((quad_t)howmany(p- >fts_number, blocksize), + p->fts_path, hflag); break; case FTS_DC: /* Ignore. */ break; @@ -324,6 +334,6 @@ usage(void) { (void)fprintf(stderr, - "usage: du [-a | -s] [-chkrx] [-H | -L | -P] [file ...]\n"); + "usage: du [-a | -s] [-chkrx] [-d depth] [-H | -L | - P] [file ...]\n"); exit(1); } |