/var/log/lastlog
is a binary file used in "random access" mode rather than a log appended to, and is thus naturally a sparse file, as noted in this (GNU/Linux) manual:
NOTE
The lastlog file is a database which contains info on the last login
of each user. You should not rotate it. It is a sparse file, so its
size on the disk is usually much smaller than the one shown by "ls -l"
(which can indicate a really big file if you have in passwd users with
a high UID). You can display its real size with "ls -s".
Sparse means its actual disk usage is less than its apparent size.
On GNU/Linux, the -b
option for du
is described as:
-b
, --bytes
equivalent to --apparent-size --block-size=1
That is, -b
explicitly disables the sparse file detection and handling by including --apparent-size
.
So to have size in bytes match -k
(on-disk actual usage) use instead:
du --block-size=1 /var/log/lastlog
or to have size in KiB match -b
(with apparent size) use instead:
du --apparent-size -k /var/log/lastlog