linux上的查找命令Find
语法:
find path -option [ -print ] [ -exec -ok command ] {} ;
菜鸟教程:https://www.runoob.com/linux/linux-comm-find.html
案例:
1、查找大于100M的文件
$find . -type f -size +1000000k
2、Linux查找快速增长的文件(查找近期变动的大小超过M的文件)
$ du -sh `find ./ -ctime 0` | grep [0-9]M | sort -n
3、linux统计目录大小并排序 查看目录下所有一级子目录文件夹大小
格式:du -h --max-depth=1 |grep []
$du -h --max-depth=1 |grep [TG] |sort #查找上G和T的目录并排序
4、搜索指定日期范围的文件,例如搜索/test下2017-06-03到2017-06-06之间修改过的文件
$find /test -type f -newermt 2017-06-03 -a ! -newermt 2018-06-06
linux上的统计命令du:
Linux du命令用于显示目录或文件的大小。
du会显示指定的目录或文件所占用的磁盘空间。
语法:
du [-abcDhHklmsSx][-L <符号连接>][-X <文件>][--block-size][--exclude=<目录或文件>][--max-depth=<目录层数>][--help][--version][目录或文件]
菜鸟教程:https://www.runoob.com/linux/linux-comm-du.html
案例:
1、统计当前目录的大小,以直观方式展现
$du -sh
2、查看上G目录并排序
$du -h --max-depth=1 |grep 'G' |sort
3、查看当前目录下所有一级子目录文件夹大小
$du -sh --max-depth=1
4、查看当前目录下所有一级子目录文件夹大小 并排序
$du -h --max-depth=1 |sort
5、查看当前目录下所有一级子目录文件夹大小 并排序
$du -h --max-depth=1 |grep [TG] |sort -nr
倒序排
6、统计多个文件总大小
# -c:总大小,-m:以M为单位 $ find ./ -iname "*.py" | xargs du -cm