Add two new options to du(1):
-A Display the apparent size instead of the disk usage. This can be helpful when operating on compressed volumes or sparse files. -B blocksize Calculate block counts in blocksize byte blocks. This is differ- ent from the -k, -m options or setting BLOCKSIZE and gives an estimate of how much space the examined file hierachy would require on a filesystem with the given blocksize. Unless in -A mode, blocksize is rounded up to the next multiple of 512. The former is similar to GNU's du(1) --apparent-size. The latter is different from what GNU's du(1) -B does, which is equivalent to setting BLOCKSIZE in our implementation and is rather pointless as it doesn't add any real value (i.e. you can achieve the same with a simple awk-script). No change in the normal output or processing. Reviewed by: keramida@, Peter French Otherwise silience from: freebsd-hackers@
This commit is contained in:
parent
c38116e6bb
commit
fd543f2759
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=184733
@ -32,7 +32,7 @@
|
|||||||
.\" @(#)du.1 8.2 (Berkeley) 4/1/94
|
.\" @(#)du.1 8.2 (Berkeley) 4/1/94
|
||||||
.\" $FreeBSD$
|
.\" $FreeBSD$
|
||||||
.\"
|
.\"
|
||||||
.Dd February 25, 2008
|
.Dd November 6, 2008
|
||||||
.Dt DU 1
|
.Dt DU 1
|
||||||
.Os
|
.Os
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@ -40,11 +40,12 @@
|
|||||||
.Nd display disk usage statistics
|
.Nd display disk usage statistics
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
|
.Op Fl A
|
||||||
.Op Fl H | L | P
|
.Op Fl H | L | P
|
||||||
.Op Fl a | s | d Ar depth
|
.Op Fl a | s | d Ar depth
|
||||||
.Op Fl c
|
.Op Fl c
|
||||||
.Op Fl l
|
.Op Fl l
|
||||||
.Op Fl h | k | m
|
.Op Fl h | k | m | B Ar blocksize
|
||||||
.Op Fl n
|
.Op Fl n
|
||||||
.Op Fl x
|
.Op Fl x
|
||||||
.Op Fl I Ar mask
|
.Op Fl I Ar mask
|
||||||
@ -60,6 +61,25 @@ the current directory is displayed.
|
|||||||
.Pp
|
.Pp
|
||||||
The options are as follows:
|
The options are as follows:
|
||||||
.Bl -tag -width indent
|
.Bl -tag -width indent
|
||||||
|
.It Fl A
|
||||||
|
Display the apparent size instead of the disk usage.
|
||||||
|
This can be helpful when operating on compressed volumes or sparse files.
|
||||||
|
.It Fl B Ar blocksize
|
||||||
|
Calculate block counts in
|
||||||
|
.Ar blocksize
|
||||||
|
byte blocks.
|
||||||
|
This is different from the
|
||||||
|
.Fl k, m
|
||||||
|
options or setting
|
||||||
|
.Ev BLOCKSIZE
|
||||||
|
and gives an estimate of how much space the examined file hierachy would
|
||||||
|
require on a filesystem with the given
|
||||||
|
.Ar blocksize .
|
||||||
|
Unless in
|
||||||
|
.Fl A
|
||||||
|
mode,
|
||||||
|
.Ar blocksize
|
||||||
|
is rounded up to the next multiple of 512.
|
||||||
.It Fl H
|
.It Fl H
|
||||||
Symbolic links on the command line are followed, symbolic links in file
|
Symbolic links on the command line are followed, symbolic links in file
|
||||||
hierarchies are not followed.
|
hierarchies are not followed.
|
||||||
@ -136,14 +156,19 @@ followed is not counted or displayed.
|
|||||||
If the environment variable
|
If the environment variable
|
||||||
.Ev BLOCKSIZE
|
.Ev BLOCKSIZE
|
||||||
is set, and the
|
is set, and the
|
||||||
.Fl k
|
.Fl k, m
|
||||||
option is not specified, the block counts will be displayed in units of that
|
or
|
||||||
size block.
|
.Fl h
|
||||||
|
options are not specified, the block counts will be displayed in units of
|
||||||
|
that block size.
|
||||||
If
|
If
|
||||||
.Ev BLOCKSIZE
|
.Ev BLOCKSIZE
|
||||||
is not set, and the
|
is not set, and the
|
||||||
.Fl k
|
.Fl k, m
|
||||||
option is not specified, the block counts will be displayed in 512-byte blocks.
|
or
|
||||||
|
.Fl h
|
||||||
|
options are not specified, the block counts will be displayed in 512-byte
|
||||||
|
blocks.
|
||||||
.El
|
.El
|
||||||
.Sh SEE ALSO
|
.Sh SEE ALSO
|
||||||
.Xr df 1 ,
|
.Xr df 1 ,
|
||||||
|
@ -79,14 +79,15 @@ static void ignoreclean(void);
|
|||||||
static int ignorep(FTSENT *);
|
static int ignorep(FTSENT *);
|
||||||
|
|
||||||
static int nodumpflag = 0;
|
static int nodumpflag = 0;
|
||||||
|
static int Aflag;
|
||||||
|
static long blocksize, cblocksize;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
FTS *fts;
|
FTS *fts;
|
||||||
FTSENT *p;
|
FTSENT *p;
|
||||||
off_t savednumber;
|
off_t savednumber, curblocks;
|
||||||
long blocksize;
|
|
||||||
int ftsoptions;
|
int ftsoptions;
|
||||||
int listall;
|
int listall;
|
||||||
int depth;
|
int depth;
|
||||||
@ -98,16 +99,30 @@ main(int argc, char *argv[])
|
|||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
|
|
||||||
Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
|
Hflag = Lflag = Pflag = aflag = sflag = dflag = cflag = hflag =
|
||||||
lflag = 0;
|
lflag = Aflag = 0;
|
||||||
|
|
||||||
save = argv;
|
save = argv;
|
||||||
ftsoptions = 0;
|
ftsoptions = 0;
|
||||||
savednumber = 0;
|
savednumber = 0;
|
||||||
|
cblocksize = DEV_BSIZE;
|
||||||
|
blocksize = 0;
|
||||||
depth = INT_MAX;
|
depth = INT_MAX;
|
||||||
SLIST_INIT(&ignores);
|
SLIST_INIT(&ignores);
|
||||||
|
|
||||||
while ((ch = getopt(argc, argv, "HI:LPasd:chklmnrx")) != -1)
|
while ((ch = getopt(argc, argv, "AB:HI:LPasd:chklmnrx")) != -1)
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
case 'A':
|
||||||
|
Aflag = 1;
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
errno = 0;
|
||||||
|
cblocksize = atoi(optarg);
|
||||||
|
if (errno == ERANGE || cblocksize <= 0) {
|
||||||
|
warnx("invalid argument to option B: %s",
|
||||||
|
optarg);
|
||||||
|
usage();
|
||||||
|
}
|
||||||
|
break;
|
||||||
case 'H':
|
case 'H':
|
||||||
Hflag = 1;
|
Hflag = 1;
|
||||||
break;
|
break;
|
||||||
@ -144,22 +159,18 @@ main(int argc, char *argv[])
|
|||||||
cflag = 1;
|
cflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
if (setenv("BLOCKSIZE", "512", 1) == -1)
|
|
||||||
warn("setenv: cannot set BLOCKSIZE=512");
|
|
||||||
hflag = 1;
|
hflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'k':
|
case 'k':
|
||||||
hflag = 0;
|
hflag = 0;
|
||||||
if (setenv("BLOCKSIZE", "1024", 1) == -1)
|
blocksize = 1024;
|
||||||
warn("setenv: cannot set BLOCKSIZE=1024");
|
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
lflag = 1;
|
lflag = 1;
|
||||||
break;
|
break;
|
||||||
case 'm':
|
case 'm':
|
||||||
hflag = 0;
|
hflag = 0;
|
||||||
if (setenv("BLOCKSIZE", "1048576", 1) == -1)
|
blocksize = 1048576;
|
||||||
warn("setenv: cannot set BLOCKSIZE=1048576");
|
|
||||||
break;
|
break;
|
||||||
case 'n':
|
case 'n':
|
||||||
nodumpflag = 1;
|
nodumpflag = 1;
|
||||||
@ -206,6 +217,9 @@ main(int argc, char *argv[])
|
|||||||
if (Pflag)
|
if (Pflag)
|
||||||
ftsoptions |= FTS_PHYSICAL;
|
ftsoptions |= FTS_PHYSICAL;
|
||||||
|
|
||||||
|
if (!Aflag && (cblocksize % DEV_BSIZE) != 0)
|
||||||
|
cblocksize = howmany(cblocksize, DEV_BSIZE) * DEV_BSIZE;
|
||||||
|
|
||||||
listall = 0;
|
listall = 0;
|
||||||
|
|
||||||
if (aflag) {
|
if (aflag) {
|
||||||
@ -224,8 +238,13 @@ main(int argc, char *argv[])
|
|||||||
argv[1] = NULL;
|
argv[1] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)getbsize(¬used, &blocksize);
|
if (blocksize == 0)
|
||||||
blocksize /= 512;
|
(void)getbsize(¬used, &blocksize);
|
||||||
|
|
||||||
|
if (!Aflag) {
|
||||||
|
cblocksize /= DEV_BSIZE;
|
||||||
|
blocksize /= DEV_BSIZE;
|
||||||
|
}
|
||||||
|
|
||||||
rval = 0;
|
rval = 0;
|
||||||
|
|
||||||
@ -242,17 +261,19 @@ main(int argc, char *argv[])
|
|||||||
if (ignorep(p))
|
if (ignorep(p))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
curblocks = Aflag ?
|
||||||
|
howmany(p->fts_statp->st_size, cblocksize) :
|
||||||
|
howmany(p->fts_statp->st_blocks, cblocksize);
|
||||||
p->fts_parent->fts_bignum += p->fts_bignum +=
|
p->fts_parent->fts_bignum += p->fts_bignum +=
|
||||||
p->fts_statp->st_blocks;
|
curblocks;
|
||||||
|
|
||||||
if (p->fts_level <= depth) {
|
if (p->fts_level <= depth) {
|
||||||
if (hflag) {
|
if (hflag) {
|
||||||
prthumanval(howmany(p->fts_bignum,
|
prthumanval(p->fts_bignum);
|
||||||
blocksize));
|
|
||||||
(void)printf("\t%s\n", p->fts_path);
|
(void)printf("\t%s\n", p->fts_path);
|
||||||
} else {
|
} else {
|
||||||
(void)printf("%jd\t%s\n",
|
(void)printf("%jd\t%s\n",
|
||||||
(intmax_t)howmany(p->fts_bignum,
|
howmany(p->fts_bignum * cblocksize,
|
||||||
blocksize), p->fts_path);
|
blocksize), p->fts_path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -273,21 +294,22 @@ main(int argc, char *argv[])
|
|||||||
linkchk(p))
|
linkchk(p))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
curblocks = Aflag ?
|
||||||
|
howmany(p->fts_statp->st_size, cblocksize) :
|
||||||
|
howmany(p->fts_statp->st_blocks, cblocksize);
|
||||||
|
|
||||||
if (listall || p->fts_level == 0) {
|
if (listall || p->fts_level == 0) {
|
||||||
if (hflag) {
|
if (hflag) {
|
||||||
prthumanval(howmany(
|
prthumanval(curblocks);
|
||||||
p->fts_statp->st_blocks,
|
|
||||||
blocksize));
|
|
||||||
(void)printf("\t%s\n", p->fts_path);
|
(void)printf("\t%s\n", p->fts_path);
|
||||||
} else {
|
} else {
|
||||||
(void)printf("%jd\t%s\n",
|
(void)printf("%jd\t%s\n",
|
||||||
(intmax_t)howmany(
|
howmany(curblocks * cblocksize,
|
||||||
p->fts_statp->st_blocks,
|
blocksize), p->fts_path);
|
||||||
blocksize), p->fts_path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p->fts_parent->fts_bignum += p->fts_statp->st_blocks;
|
p->fts_parent->fts_bignum += curblocks;
|
||||||
}
|
}
|
||||||
savednumber = p->fts_parent->fts_bignum;
|
savednumber = p->fts_parent->fts_bignum;
|
||||||
}
|
}
|
||||||
@ -297,11 +319,11 @@ main(int argc, char *argv[])
|
|||||||
|
|
||||||
if (cflag) {
|
if (cflag) {
|
||||||
if (hflag) {
|
if (hflag) {
|
||||||
prthumanval(howmany(savednumber, blocksize));
|
prthumanval(savednumber);
|
||||||
(void)printf("\ttotal\n");
|
(void)printf("\ttotal\n");
|
||||||
} else {
|
} else {
|
||||||
(void)printf("%jd\ttotal\n", (intmax_t)howmany(
|
(void)printf("%jd\ttotal\n", (intmax_t)howmany(
|
||||||
savednumber, blocksize));
|
savednumber * cblocksize, blocksize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -448,7 +470,9 @@ prthumanval(int64_t bytes)
|
|||||||
{
|
{
|
||||||
char buf[5];
|
char buf[5];
|
||||||
|
|
||||||
bytes *= DEV_BSIZE;
|
bytes *= cblocksize;
|
||||||
|
if (!Aflag)
|
||||||
|
bytes *= DEV_BSIZE;
|
||||||
|
|
||||||
humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
|
humanize_number(buf, sizeof(buf), bytes, "", HN_AUTOSCALE,
|
||||||
HN_B | HN_NOSPACE | HN_DECIMAL);
|
HN_B | HN_NOSPACE | HN_DECIMAL);
|
||||||
@ -460,8 +484,9 @@ static void
|
|||||||
usage(void)
|
usage(void)
|
||||||
{
|
{
|
||||||
(void)fprintf(stderr,
|
(void)fprintf(stderr,
|
||||||
"usage: du [-H | -L | -P] [-a | -s | -d depth] [-c] "
|
"usage: du [-A] [-H | -L | -P] [-a | -s | -d depth] [-c] "
|
||||||
"[-l] [-h | -k | -m] [-n] [-x] [-I mask] [file ...]\n");
|
"[-l] [-h | -k | -m | -B bsize] [-n] [-x] [-I mask] "
|
||||||
|
"[file ...]\n");
|
||||||
exit(EX_USAGE);
|
exit(EX_USAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user