summaryrefslogtreecommitdiffstats
path: root/usr.bin/du
diff options
context:
space:
mode:
authorscrappy <scrappy@FreeBSD.org>1996-10-23 06:53:57 +0000
committerscrappy <scrappy@FreeBSD.org>1996-10-23 06:53:57 +0000
commit37eda0b07d63396a3fbbfa58f4b5390ae0f97ac5 (patch)
tree4eb11960a2f9281fc6f32b10e3fe0781bf514a55 /usr.bin/du
parentf71eaa90af7ac7591df48becb64982cffb61ea4f (diff)
downloadFreeBSD-src-37eda0b07d63396a3fbbfa58f4b5390ae0f97ac5.zip
FreeBSD-src-37eda0b07d63396a3fbbfa58f4b5390ae0f97ac5.tar.gz
Add a 'depth (-d#)' flag to du
patched (context diff), compiled (w/ -Wall) and tested Submitted by: John-Mark Gurney <jmg@nike.efn.org>
Diffstat (limited to 'usr.bin/du')
-rw-r--r--usr.bin/du/du.18
-rw-r--r--usr.bin/du/du.c33
2 files changed, 30 insertions, 11 deletions
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);
}
OpenPOWER on IntegriCloud