Bug 246122

Summary: find -size does not work properly with 'M' unit
Product: Red Hat Enterprise Linux 5 Reporter: ladislav <ladislav>
Component: findutilsAssignee: Vitezslav Crhonek <vcrhonek>
Status: CLOSED NOTABUG QA Contact:
Severity: low Docs Contact:
Priority: low    
Version: 5.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-09-25 14:15:11 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description ladislav 2007-06-28 17:29:38 UTC
Description of problem:

find -size [<mod>]<x>M does work

Version-Release number of selected component (if applicable):

4.2.27-4.1

How reproducible:

compare file sizes

Steps to Reproduce:
1. dd if=/bin/false of=onemeg bs=1024 count=1024
   dd if=/bin/false of=onemegplus bs=1024 count=1025
   dd if=/bin/false of=onemegminus bs=1024 count=1023

2. find -size 1M;find -size -1M;find -size +1M
  
Actual results:

foof@e31 m70]$ find -size 1M
./onemeg
./onemegminus
[foof@e31 m70]$ find -size -1M
[foof@e31 m70]$ find -size +1M
./onemegplus


Expected results:

[foof@e31 m70]$ find -size 1M
./onemeg
[foof@e31 m70]$ find -size -1M
./onemegminus
[foof@e31 m70]$ find -size +1M
./onemegplus


Additional info:

Comment 1 Vitezslav Crhonek 2007-09-25 14:15:11 UTC
This behaviour is correct, see the documentation:

http://www.gnu.org/software/findutils/manual/html_mono/find.html.gz#Size

"True if the file uses n units of space, rounding up.". _Rounding up_! In the
package man page (including lates version) this sentence is a bit different
"File uses n units of space.". Try report bug to upstream.

With 1M, onemegminus is round to 1M, that's the reason, why find -size 1M both
files are returned. If you try your example with find {+,-, }1024k, you get what
you expect.
Maybe this will help you understand:

[vcrhonek@norcus tmp]$ ls -alh
total 29M
drwxr-xr-x  2 vcrhonek vcrhonek 4.0K Sep 25 15:47 .
drwx------ 82 vcrhonek vcrhonek 4.0K Sep 25 14:23 ..
-rw-rw-r--  1 vcrhonek vcrhonek 5.0M Sep 25 15:41 fivemeg
-rw-rw-r--  1 vcrhonek vcrhonek 4.0M Sep 25 15:45 fourmeg
-rw-rw-r--  1 vcrhonek vcrhonek 7.0M Sep 25 15:44 sevenmeg
-rw-rw-r--  1 vcrhonek vcrhonek 6.0M Sep 25 15:44 sixmeg
-rw-rw-r--  1 vcrhonek vcrhonek 3.5M Sep 25 15:47 threeandhalf
-rw-rw-r--  1 vcrhonek vcrhonek 3.0M Sep 25 15:44 threemeg
[vcrhonek@norcus tmp]$ find -size 5M
./fivemeg
[vcrhonek@norcus tmp]$ find -size 4M
./fourmeg
./threeandhalf
[vcrhonek@norcus tmp]$ find -size -4M
./threemeg

Comment 2 ladislav 2007-09-25 16:36:34 UTC
Thanks for pointing out the rounding up.

Very counter intuitive and twisted imnsho, but as you point out, correct
behavior per the man page.  (Compare with same in k units for example.)