2.6 Size

Test: -size n[bckwMG]

True if the file uses n units of space, rounding up. The units are 512-byte blocks by default, but they can be changed by adding a one-character suffix to n:

b

512-byte blocks (never 1024)

c

bytes

w

2-byte words

k

Kibibytes (KiB, units of 1024 bytes)

M

Mebibytes (MiB, units of 1024 * 1024 = 1048576 bytes)

G

Gibibytes (GiB, units of 1024 * 1024 * 1024 = 1073741824 bytes)

The ‘b’ suffix always considers blocks to be 512 bytes. This is not affected by the setting (or non-setting) of the POSIXLY_CORRECT environment variable. This behaviour is different from the behaviour of the ‘-ls’ action). If you want to use 1024-byte units, use the ‘k’ suffix instead.

The number can be prefixed with a ‘+’ or a ‘-’. A plus sign indicates that the test should succeed if the file uses at least n units of storage (a common use of this test) and a minus sign indicates that the test should succeed if the file uses less than n units of storage; i.e., an exact size of n units does not match. Bear in mind that the size is rounded up to the next unit. Therefore ‘-size -1M’ is not equivalent to ‘-size -1048576c’. The former only matches empty files, the latter matches files from 0 to 1,048,575 bytes. There is no ‘=’ prefix, because that’s the default anyway.

The size is simply the st_size member of the struct stat populated by the lstat (or stat) system call, rounded up as shown above. In other words, it’s consistent with the result you get for ‘ls -l’. This handling of sparse files differs from the output of the ‘%k’ and ‘%b’ format specifiers for the ‘-printf’ predicate.

Test: -empty

True if the file is empty and is either a regular file or a directory. This might help determine good candidates for deletion. This test is useful with ‘-depth’ (see Directories) and ‘-delete’ (see Single File).