Unix Technical Forum

-d support for du

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > OpenBSD > mailing.openbsd.tech

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-18-2008, 08:47 AM
David Chisnall
 
Posts: n/a
Default -d support for du

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);
}

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:07 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com