发现linux命令/工具find的一个”bug”
今天用find命令找一个目录下面所有大小小于1K的普通文件. 我的命令是这么写的: $ find ~ -type f -a -size -1K | wc -l 发现得到的数字明显比预想的小很多。但命令没错呀百思不得其解之下,又试了一下另一种写法。这时,就正常了,真奇怪啊 $ find ~ -type f -a -size -1024c | wc -l 这次就正常了!!! 我反复查文档: c for bytes K for Kilobytes (units of 1024 bytes) 对啊没错啊。 1K就是1024byte。哪里出问题了,哪出出错了呢?难道是linux的bug吗?我换了一个发行版的linux,发现还是同样的情况。这就郁闷了 再次查看文档,这次详细读文档了!终于发现问题所在了: The + and – prefixes signify greater than and less than, as usual. 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 1 to 1,048,575 bytes. ...