find -size -Nk seems to be off by 1

Bug #1385813 reported by LukeKendall on 2014-10-26
This bug affects 1 person
Affects Status Importance Assigned to Milestone
findutils (Ubuntu)

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
$ find testf -size -2k -print
$ find testf -size -3k -print
$ find --version
find (GNU findutils) 4.4.2
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <>
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 e5573b1bad88bfabcda181b9e0125fb0c52b7d3b
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.

LukeKendall (luke-zeta) wrote :

The -size -nnnnnX check works like this:

How many units sized one X each is the file using,
a) less than nnnnn
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

Changed in findutils (Ubuntu):
status: New → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers