Answers:
采用:
find . -type f -size +4096c
查找大于4096字节的文件。
和:
find . -type f -size -4096c
查找小于4096字节的文件。
注意大小切换后的+和-差异。
该-size
开关解释说:
-size n[cwbkMG]
File uses n units of space. The following suffixes can be used:
`b' for 512-byte blocks (this is the default if no suffix is
used)
`c' for bytes
`w' for two-byte words
`k' for Kilobytes (units of 1024 bytes)
`M' for Megabytes (units of 1048576 bytes)
`G' for Gigabytes (units of 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 1 Kilobyte blocks, which is different
to the behaviour of -ls.
对于这类事情,AWK确实很容易。您可以根据要求在文件大小检查方面进行以下操作:
列出大于200个字节的文件:
ls -l | awk '{if ($5 > 200) print $8}'
列出少于200个字节的文件,并将列表写入文件:
ls -l | awk '{if ($5 < 200) print $8}' | tee -a filelog
列出0字节的文件,将列表记录到文件中并删除空文件:
ls -l | awk '{if ($5 == 0) print $8}' | tee -a deletelog | xargs rm
tee
和直接重定向到文件(如ls -l > filelog
或ls -l >> filelog
)有什么区别?