coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sorting of 'du' input


From: Bernhard Voelker
Subject: Re: Sorting of 'du' input
Date: Mon, 20 May 2024 14:23:11 +0200
User-agent: Mozilla Thunderbird



On 5/11/24 23:54, Karl-Heinz Oliv via GNU coreutils General Discussion wrote:
> Hi,
>
> I am having problems with the evaluation/output order of 'du (GNU
> coreutils) 8.32'.First tests below show that glob expansion of '*' and
> language specific sorting work as expected. 'du' intrinsic sorting of
> dirs is reverse order. Cumbersome, but follows manpage description.
>
> But last tests show that there is no sorting for files.
>
> I found general hints at the coreutils web resources regarding sorting
> issues, but nothing regarding the combination of sorted glob expansion
> with reverse dir sorting of 'du' or unsorted file order of 'du' output.
> E.g. 'du -a *'
>
> Of course post-processing the output, using a different command, or
> writing a script could work around. But the beauty of 'du' is/always was
> its simplicity (e.g. in 'watch' command).
>
> In case other coreutil commands show the same behavior, why not to
> introduce a '--sort'option, which applies the language specific sort
> order refered to in 'LC_COREUTILS=...'? If LC_COREUTILS does not exist
> or is "", then apply LC_ALL. If this does not exist or is empty, then
> ignore '--sort'.
>
> Actually, the sort order usually does not play a big role, as long as
> *everything* is sorted the same way. It is the mixture that causes the
> problem. If LC_COREUTILS does not fit the development strategy, would it
> be possible to define an alias for 'du' and 'du -a', which is always
> based on 'du *'? Unfortunately I am not experienced enough to find out
> an expression, which works with all file / dir names and combinations of
> 'du' options.

Did you try 'du .' instead of 'du *'?  That would avoid the globbing and
hence the sorting by that.

> Or is there a simple solution which I have missed?

https://www.gnu.org/software/coreutils/rejected_requests.html#du

Furthermore, there are several possibilities for sorting - depending on
what you actually want to see.

E.g. sort all regular files by their size (+human-readable):

  $ find -type f -print0 | du --files0-from=- -sh | sort -k1,1h

Or the following is what I'm using quite often on the terminal to find
the big ones:

  $ du -shxc * | sort -h
or
  $ du -xchd 2 | sort -h

Have a nice day,
Berny




reply via email to

[Prev in Thread] Current Thread [Next in Thread]