find命令的-size 100k参数使用千字节还是千二进制字节?
find's -size Unit Confusion Great question—this is a super common pain point thanks to overlapping terminology between traditional Unix conventions and modern unit standards. Let’s break this down clearly:
The Short Answer
The find command’s -size k option actually uses 1024 bytes (what’s now formally called a kibibyte, KiB), even though the man page incorrectly labels it as a "kilobyte" (which should be 1000 bytes). This is a historical terminology holdover, not a functional bug.
How to Verify It Yourself
You can easily test this behavior with a couple of quick commands:
- Create a file exactly 1024 bytes long:
dd if=/dev/zero of=test-1024b bs=1 count=1024 - Create a file exactly 1000 bytes long:
dd if=/dev/zero of=test-1000b bs=1 count=1000 - Now run
findwith the-size 1kfilter:
This will only returnfind . -size 1ktest-1024b, confirming thatkmaps to 1024 bytes.
What About 1000-byte "Kilobytes"?
Many modern versions of find (like GNU find, the default on most Linux distros) support a uppercase K to explicitly denote 1000-byte units. If you run:
find . -size 1K
It will only return test-1000b, aligning with the formal kilobyte definition.
Why the Man Page is Wrong
This mismatch comes from history: When Unix tools like find were first written, the term "kilobyte" was commonly used to mean 1024 bytes, long before the IEC introduced the kibibyte (KiB) and mebibyte (MiB) terms to distinguish binary vs decimal units. Most man pages haven’t been updated to reflect this modern terminology standard, leading to the confusion you noticed.
内容的提问来源于stack exchange,提问作者user3002473

