coreutils
[Top][All Lists]
Advanced

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

Sorting of 'du' input


From: Karl-Heinz Oliv
Subject: Sorting of 'du' input
Date: Sat, 11 May 2024 23:54:51 +0200

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.


Or is there a simple solution which I have missed?

Thank you for any response.


*Environment:**
*
LANGUAGE=
LANG=de_DE.UTF-8
LC_ALL not set, but neither =C nor =POSIX had an impact.
LC_...=de_DE.UTF-8 (all others)


*Test Setup (mind the order):**
*
touch 2.txt
touch 1.txt
touch 3.txt

mkdir b
touch b/2b.txt
touch b/1b.txt
touch b/3b.txt

mkdir a
touch a/2a.txt
touch a/1a.txt
touch a/3a.txt

mkdir c
touch c/2c.txt
touch c/1c.txt
touch c/3c.txt


*Tests (sorted order as expected):**
*
ls
-----
1.txt  2.txt  3.txt  a  b  c

ls -R
-----
.:
1.txt  2.txt  3.txt  a  b  c

./a:
1a.txt  2a.txt  3a.txt

./b:
1b.txt  2b.txt  3b.txt

./c:
1c.txt  2c.txt  3c.txt


ls *
-----
1.txt  2.txt  3.txt

a:
1a.txt  2a.txt  3a.txt

b:
1b.txt  2b.txt  3b.txt

c:
1c.txt  2c.txt  3c.txt



du *
-----
0       1.txt
0       2.txt
0       3.txt
4       a
4       b
4       c



*Test (reverse order. Cumbersome, but as described in man page):
*
du
-----
4       ./c
4       ./b
4       ./a

*Test (file order not sorted at 1st and 2nd level):
*
du -a
-----
0       ./2.txt
0       ./c/3c.txt
0       ./c/2c.txt
0       ./c/1c.txt
4       ./c
0       ./1.txt
0       ./b/2b.txt
0       ./b/1b.txt
0       ./b/3b.txt
4       ./b
0       ./a/3a.txt
0       ./a/1a.txt
0       ./a/2a.txt
4       ./a
0       ./3.txt


*Test (1st level sorted. 2nd level files not sorted - identical to above):**
***
du -a *
-------
0       1.txt
0       2.txt
0       3.txt
0       a/3a.txt
0       a/1a.txt
0       a/2a.txt
4       a
0       b/2b.txt
0       b/1b.txt
0       b/3b.txt
4       b
0       c/3c.txt
0       c/2c.txt
0       c/1c.txt
4       c




reply via email to

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