在终端中,如何查找大于或小于X字节的文件?
![062795e27c4f978fd95162a8d061d195.png](https://i-blog.csdnimg.cn/blog_migrate/dca840625f4824f7ded72fe8bb085dff.jpeg)
首先你想到的可能是
find . -exec ls -l {} ;
然后AWK通过文件大小将结果传递给过滤器。但应该有比这更简单的方法吧?
AWK是一种专为文本处理而设计的编程语言,通常用作数据提取和报告工具。它是大多数类Unix 操作系统的标准功能。
有!你可以使用:
find . -type f -size +4096c查找大于4096字节的文件。 find . -type f -size -4096c查找小于4096字节的文件。
其他方法:
列出大于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