1: 如何查找大文件?
搜索当前目录下,超过100M大小的文件:
[root@getlnx01 u03]# find . -type f -size +100M./usr/local/jdk-7u67-linux-x64.tar.gz./data/log/charge-service/test-access.log.2016-08-08.log./data/log/aaa_service/test-access.log.2016-08-09.log./home/deploy/logs/testmqlogs/otherdays/testmq_client.1.log./home/deploy/logs/testmqlogs/otherdays/testmq_client.2.log./opt/backend/charge-service/1.2/shared/console.log./opt/backend/express_service/0.0.3.tar.gz./opt/backend/aaa-service/1.2/shared/console.log
更详细显示一些文件属性或信息:
[root@getlnx01 u03]# find . -type f -size +100M -print0 | xargs -0 ls -l-rw-rw-r-- 1 deploy deploy 542795006 8月 30 15:14 ./data/log/charge-service/test-access.log.2016-08-08.log-rw-rw-r-- 1 deploy deploy 225658142 8月 25 16:28 ./data/log/aaa_service/test-access.log.2016-08-09.log-rw-rw-r-- 1 deploy deploy 253623621 8月 30 15:15 ./home/deploy/logs/testmqlogs/otherdays/testmq_client.1.log-rw-rw-r-- 1 deploy deploy 373547598 8月 25 16:28 ./home/deploy/logs/testmqlogs/otherdays/testmq_client.2.log-rw-rw-r-- 1 deploy deploy 645631934 8月 30 15:15 ./opt/backend/charge-service/1.2/shared/console.log-rw-rw-r-- 1 deploy deploy 209314900 8月 30 15:15 ./opt/backend/aaa-service/1.2/shared/console.log-rw-r--r-- 1 root root 315334884 12月 21 2015 ./opt/backend/express_service/0.0.3.tar.gz-rw-r--r-- 1 root root 142376665 6月 11 2015 ./usr/local/jdk-7u67-linux-x64.tar.gz-rw-rw-r-- 1 deploy deploy 105085974 8月 30 15:15 ./usr/local/push-tomcat/logs/push/info.log6829699375703641.tmp
当我们只需要查找超过100M大小文件,并显示查找出来文件的具体大小,并排序(下)
[root@getlnx01 u03]# find . -type f -size +100M -print0 | xargs -0 du -h102M ./usr/local/push-tomcat/logs/push/info.log6829699375703641.tmp136M ./usr/local/jdk-7u67-linux-x64.tar.gz518M ./data/log/charge-service/test-access.log.2016-08-08.log216M ./data/log/aaa_service/test-access.log.2016-08-09.log242M ./home/deploy/logs/testmqlogs/otherdays/testmq_client.1.log357M ./home/deploy/logs/testmqlogs/otherdays/testmq_client.2.log616M ./opt/backend/charge-service/1.2/shared/console.log301M ./opt/backend/express_service/0.0.3.tar.gz201M ./opt/backend/aaa-service/1.2/shared/console.log
[root@getlnx01 u03]# find . -type f -size +100M -print0 | xargs -0 du -h | sort -nr616M ./opt/backend/charge-service/1.2/shared/console.log518M ./data/log/charge-service/test-access.log.2016-08-08.log357M ./home/deploy/logs/testmqlogs/otherdays/testmq_client.2.log301M ./opt/backend/express_service/0.0.3.tar.gz243M ./home/deploy/logs/testmqlogs/otherdays/testmq_client.1.log216M ./data/log/aaa_service/test-access.log.2016-08-09.log201M ./opt/backend/aaa-service/1.2/shared/console.log
不过如上截图所示,有时候排列的顺序并不完全是按大小一致,这个是因为du命令的参数h所致,你可以统一使用使用MB来显示,这样就能解决这个问题。到这里,这个在Linux系统查找大文件的命令已经非常完美了,当然如果你还有很多的需求,那么可以在这个命令上做修改、调整.
2: 如何查找Linux下的大目录
譬如有时候磁盘空间告警了,而你平时又疏于管理、监控文件的增长,那么我需要快速的了解哪些目录变得比较大,那么此时我们可以借助du命令来帮我们解决这个问题。
[root@getlnx01 u03]# du -h --max-depth=116K ./lost+found33G ./flash_recovery_area37G ./oradata70G .如果你想知道flash_recovery_area目录下面有哪些大文件夹,那么可以将参数max-depth=2 ,如果你想对搜索出来的结果进行排序,那么可以借助于sort命令。如下所示
[root@getlnx01 u03]# du -h --max-depth=2 | sort -n3.5G ./flash_recovery_area/EPPS16K ./lost+found29G ./flash_recovery_area/backup33G ./flash_recovery_area37G ./oradata37G ./oradata/epps70G .[root@getlnx01 u03]# du -hm --max-depth=2 | sort -n1 ./lost+found3527 ./flash_recovery_area/EPPS29544 ./flash_recovery_area/backup33070 ./flash_recovery_area37705 ./oradata37705 ./oradata/epps70775 .
有时候搜索出来的结果太多了(譬如,我从根目录开始搜索),一直在刷屏,如果我只想查出最大的12个文件夹,怎么办呢?此时就要借助head命令来显示了
[root@getlnx01 /]# du -hm --max-depth=2 | sort -nr | head -12407480 .167880 ./u04158685 ./u02/oradata158685 ./u02152118 ./u04/oradata70775 ./u0337705 ./u03/oradata33070 ./u03/flash_recovery_area5995 ./u01/app5995 ./u013551 ./usr1558 ./usr/share
参考资料: