Consider the following: root@freebsd:/bin # du -h -d1 -t 200000000 /usr 275M /usr/bin 992M /usr/lib 478M /usr/local 296M /usr/lib32 2.2G /usr root@freebsd:/bin # du -h -d1 -t -200000000 /usr 27M /usr/include 40K /usr/libdata 3.6M /usr/libexec 19M /usr/sbin 110M /usr/share 96M /usr/tests 144K /usr/home This is correct. However: root@freebsd:/bin # du -aht 20000000 16K ./cat 12K ./chflags 20K ./chio 12K ./chmod 24K ./cp 24K ./date 32K ./dd 16K ./df 8.0K ./domainname 8.0K ./echo 52K ./ed 24K ./expr 4.0K ./freebsd-version 12K ./getfacl 8.0K ./hostname 8.0K ./kenv 12K ./kill 12K ./ln 36K ./ls 8.0K ./mkdir 16K ./mv 104K ./pax 20K ./pkill 48K ./ps 12K ./pwait 8.0K ./pwd 8.0K ./realpath 16K ./rm 8.0K ./rmdir 24K ./setfacl 160K ./sh 8.0K ./sleep 24K ./stty 8.0K ./sync 16K ./test 12K ./uuidgen 76K ./rmail 448K ./csh 0B ./ksh root@freebsd:/bin # du -aht -20000000 16K ./cat 12K ./chflags 20K ./chio 12K ./chmod 24K ./cp 24K ./date 32K ./dd 16K ./df 8.0K ./domainname 8.0K ./echo 52K ./ed 24K ./expr 4.0K ./freebsd-version 12K ./getfacl 8.0K ./hostname 8.0K ./kenv 12K ./kill 12K ./ln 36K ./ls 8.0K ./mkdir 16K ./mv 104K ./pax 20K ./pkill 48K ./ps 12K ./pwait 8.0K ./pwd 8.0K ./realpath 16K ./rm 8.0K ./rmdir 24K ./setfacl 160K ./sh 8.0K ./sleep 24K ./stty 8.0K ./sync 16K ./test 12K ./uuidgen 76K ./rmail 448K ./csh 0B ./ksh 1.3M . I'd expect at least one of these to produce 0 output, but both of them output everything. du(1) says: -t threshold Display only entries for which size exceeds threshold. If threshold is negative, display only entries for which size is less than the absolute value of threshold. explicitly mentioning "entries", not just directories (coreutils du, where -t originates, handles this as expected).
^Triage: this does not seem to be actively in progress.
Created attachment 247720 [details] Add threshold check to regular files, patch for file /usr/src/usr.bin/du/du.c
Created attachment 247722 [details] Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh
Hello, I had a look, and the original implementation of the du threshold was only checking the threshold for directory type files. The threshold wasn't being checked for regular files, i.e. when the -a flag was set. I have created a patch that applies the same threshold check also for regular files. I also created a patch that adds a test for the du -t behaviour. I checked the patch and ran the du kyua test on 14.0-RELEASE and 15.0-CURRENT.
Created attachment 258064 [details] Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh ^Triage: rebase patch.
Created attachment 258065 [details] Add threshold check to regular files, patch for file /usr/src/usr.bin/du/du.c ^Triage: rebase patch.
Created attachment 258066 [details] Add du -t test, patch for file /usr/src/usr.bin/du/tests/du_test.sh ^Triage: rebase patch.
I added some more tests, rebased and updated the patch. I have made a pull request with the changes to github. https://github.com/freebsd/freebsd-src/pull/1648
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=0ae2b9e866d3aea1e9141841488561f12603f879 commit 0ae2b9e866d3aea1e9141841488561f12603f879 Author: Michal Scigocki <michal.os@hotmail.com> AuthorDate: 2025-04-07 11:14:44 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2025-04-28 18:20:37 +0000 du: Fix threshold on non-directory files PR: 265200 Reviewed by: markj MFC after: 1 month Pull Request: https://github.com/freebsd/freebsd-src/pull/1648 usr.bin/du/du.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)