problem description
I was using find(GNU version) to find files with size between 4G - 5G with below command
# find . -size +4G -size -5G -exec ls -1hSs {} +
But below can work
# find . -size +4G -size -6G -exec ls -1hSs {} +
4.9G ./ff84e49c231a00b2d7ed40e0ecf81cad220795bd
4.5G ./ff623cd1cdad094be418aec445e5317156e945fe
I read the man page of find get below:
`G' for Gibibytes (GiB, units of 1024 * 1024 * 1024 = 1073741824 bytes)
The size does not count indirect blocks, but it does count blocks in sparse files that are not actually allocated. Bear in mind that the `%k' and `%b'
format specifiers of -printf handle sparse files differently. The `b' suffix always denotes 512-byte blocks and never 1024-byte blocks, which is differ‐
ent to the behaviour of -ls.
And man page of ls get below but still got confused:
-h, --human-readable
with -l and/or -s, print human readable sizes (e.g., 1K 234M 2G)
The SIZE argument is an integer and optional unit (example: 10K is 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).
G
, a given size is rounded to some integer number of gibibytes. This number cannot be greater than 4 (+4G
) and less than 5 (-5G
) at the same time. No such integer exists. OTOH+4G
and-6G
are both satisfied when the number happens to be 5. – Kamil Maciorowski Mar 15 '23 at 08:12