mirror of
https://github.com/freebsd/freebsd-src
synced 2024-11-05 18:22:52 +00:00
Add a 'depth (-d#)' flag to du
patched (context diff), compiled (w/ -Wall) and tested Submitted by: John-Mark Gurney <jmg@nike.efn.org>
This commit is contained in:
parent
845c4ec464
commit
0282769e2d
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=19120
2 changed files with 30 additions and 11 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue