small change to du, so it will accepts unit suffixes for
negative thresholds
Jason Hellenthal
jhellenthal at dataix.net
Fri Mar 2 16:39:44 UTC 2012
On Fri, Mar 02, 2012 at 10:33:33AM +0000, Alexander Best wrote:
> On Fri Mar 2 12, Jason Hellenthal wrote:
> >
> >
> > On Thu, Mar 01, 2012 at 11:38:22PM +0000, Alexander Best wrote:
> > > hi there,
> > >
> > > i just noticed that du will not accepts something like the following:
> > >
> > > du -t-500M
> > >
> > > whereas
> > >
> > > du -t500M
> > >
> > > will work. i've attached a patch, which makes unit suffixes in connection with
> > > negative thresholds possible.
> > >
> >
> > I don't get it. I just ran both instances of what you have above without
> > your patch on 8-STABLE i386 and both work as intended. Are you seeing
> > something I am not ?
>
> you are right. there seems to have been a du change between 8-STABLE and HEAD,
> or maybe even in expand_number().
>
> when i run 'du -t-500M /' on HEAD i get:
>
> du: invalid threshold: -500M
> usage: du [-Aclnx] [-H | -L | -P] [-h | -k | -m ] [-a | -s | -d depth] [-B blocksize] [-I mask] [-t threshold] [file ...]
>
> ... i'll investigate some more. i also found that on 8-STABLE du isn't working
> properly in all cases. try the following:
>
> mkdir empty ; cd empty ; mkdir empty2
>
> running 'du -t-1M' should report empty2, but it doesn't. running 'du -t-2M'
> does. according to 'ls -la' an empty directory is 4096 byte. so 'du -t-4097'
> should report the empty dir; however it doesn't. du seems to quite broken when
> it comes to the -t option. have a look at the following:
>
> mkdir empty3; cd empty3; du -h -t1M
>
> reports
>
> 2,0k .
>
> that's completely wrong, since i instructed du to only display entries > 1 megabyte.
>
with locale being that of UTF-8 in an xterm I get the expected result
from this. I would expect that locale of C would do the same. It seems
that du(1) is not locale aware enough for calculating the sums and
comparing them.
I see 2,0k in your output where in mine it is 2.0
disbatch$ mkdir empty ; cd empty ; mkdir empty2
disbatch$ du -ht-1M
2.0k ./empty2
4.0k .
disbatch$ du -t-1M
2 ./empty2
4 .
disbatch$ locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_COLLATE=C
LC_TIME="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_ALL=
This was done under /bin/sh 8-STABLE i386 as of the date of this
message.
--
;s =;
More information about the freebsd-hackers
mailing list