find -size -Nk seems to be off by 1
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
findutils (Ubuntu) |
Invalid
|
Undecided
|
Unassigned |
Bug Description
If I have a file of size less than 1k, and use:
find -size -1k
to try to find it, it doesn't.
If I use
find -size -1000c
it does find it. If I use
find -size -2k
to find it, it does. It seems like the parsing of units is wrong when you use 'k' for the size units.
$ ls -l testf*
-rw-rw---- 1 luke kendall 1071 Oct 26 17:06 testf
-rw-rw---- 1 luke kendall 803 Oct 26 17:07 testf2
-rw-rw---- 1 luke kendall 963 Oct 26 17:07 testf3
$ find testf3 -size -1k -print
$ find testf3 -size -2k -print
testf3
$ find testf -size -2k -print
$ find testf -size -3k -print
testf
$ find --version
find (GNU findutils) 4.4.2
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Eric B. Decker, James Youngman, and Kevin Dalley.
Built using GNU gnulib version e5573b1bad88bfa
Features enabled: D_TYPE O_NOFOLLOW(enabled) LEAF_OPTIMISATION FTS() CBO(level=0)
$ lsb_release -rd
Description: Ubuntu 14.04.1 LTS
Release: 14.04
Package name is findutils
I expected find -size -Nk to list a file if it is smaller than N kb.
Instead, the file is only listed if it is smaller than (N+1) kb.
The -size -nnnnnX check works like this:
How many units sized one X each is the file using,
a) less than nnnnn
or
b) at least nnnnn
Therefore -size -1M or -size -1k or -size -1c all match only empty files.
A 1025 byte sized file uses two 1K-units (it has to, there is only space for 1024 bytes in a single 1K unit) and will therefore not match -size -2k.
cu Andreas