在Windows系统中,我们可以使用TreeSize工具查找一些大文件或文件夹,非常的方便高效,在Linux系统中,如何去搜索一些比较大的文件呢?下面我整理了一下在Linux系统中如何查找大文件或文件夹的方法。

1: 如何查找大文件?

 

其实很多时候,你需要了解当前系统下有哪些大文件,比如文件大小超过100M或1G(阀值视具体情况而定)。那么如何把这些大文件搜索出来呢?例如我要搜索当前目录下,超过800M大小的文件

C#代码
  1. [root@getlnx01 u03]# pwd  
  2. /u03  
  3. [root@getlnx01 u03]# find . -type f -size +800M  
  4. ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1  
  5. ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1  
  6. ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1  
  7. ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1  
  8. ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1  
  9. ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1  
  10. ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1  
  11. ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1  
  12. ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1  
  13. ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1  
  14. ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1  
  15. ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1  
  16. ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1  
  17. ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1  
  18. ./oradata/epps/invsubmat_d08.dbf  
  19. ./oradata/epps/gmtinv_d08.dbf  
  20. ./oradata/epps/gmtinv_x01.dbf  
  21. ./oradata/epps/undotbs02.dbf  
  22. ./oradata/epps/gmtinv_d07.dbf  
  23. ./oradata/epps/undotbs01.dbf  
  24. ./oradata/epps/gmtinv_x02.dbf  

如上命令所示,我们仅仅能看到超过800M大小的文件的文件名称,但是对文件的信息(例如,文件大小、文件属性)一无所知,那么能否更详细显示一些文件属性或信息呢,当然可以,如下所示

C#代码
  1. [root@getlnx01 u03]# find . -type f -size +800M  -print0 | xargs -0 ls -l  
  2. -rw-r----- 1 oracle oinstall 2782846976 Mar  6 11:51 ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1  
  3. -rw-r----- 1 oracle oinstall 1878433792 Mar  6 11:53 ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1  
  4. -rw-r----- 1 oracle oinstall 1378492416 Mar  6 11:54 ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1  
  5. -rw-r----- 1 oracle oinstall 1641381888 Mar  6 11:56 ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1  
  6. -rw-r----- 1 oracle oinstall 1564065792 Mar  6 11:58 ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1  
  7. -rw-r----- 1 oracle oinstall 1663492096 Mar  6 12:00 ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1  
  8. -rw-r----- 1 oracle oinstall 1368244224 Mar  6 12:02 ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1  
  9. -rw-r----- 1 oracle oinstall 1629069312 Mar  6 12:04 ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1  
  10. -rw-r----- 1 oracle oinstall 1629954048 Mar  6 12:06 ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1  
  11. -rw-r----- 1 oracle oinstall 1202192384 Mar  6 12:07 ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1  
  12. -rw-r----- 1 oracle oinstall 1189388288 Mar  6 12:10 ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1  
  13. -rw-r----- 1 oracle oinstall 1089257472 Mar  6 12:11 ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1  
  14. -rw-r----- 1 oracle oinstall 1097687040 Mar  6 12:12 ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1  
  15. -rw-r----- 1 oracle oinstall 1051009024 Mar  6 12:13 ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1  
  16. -rw-r----- 1 oracle oinstall 4294975488 Apr  3 15:07 ./oradata/epps/gmtinv_d07.dbf  
  17. -rw-r----- 1 oracle oinstall 4194312192 Apr  1 22:36 ./oradata/epps/gmtinv_d08.dbf  
  18. -rw-r----- 1 oracle oinstall 4294975488 Apr  3 15:54 ./oradata/epps/gmtinv_x01.dbf  
  19. -rw-r----- 1 oracle oinstall 4294975488 Apr  3 15:57 ./oradata/epps/gmtinv_x02.dbf  
  20. -rw-r----- 1 oracle oinstall 4294975488 Apr  1 22:35 ./oradata/epps/invsubmat_d08.dbf  
  21. -rw-r----- 1 oracle oinstall 8589942784 Apr  4 09:55 ./oradata/epps/undotbs01.dbf  
  22. -rw-r----- 1 oracle oinstall 8589942784 Apr  4 09:15 ./oradata/epps/undotbs02.dbf  

当我们只需要查找超过800M大小文件,并显示查找出来文件的具体大小,可以使用下面命令:

C#代码
  1. [root@getlnx01 u03]# find . -type f -size +800M  -print0 | xargs -0 du -h  
  2. 1.3G    ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1  
  3. 1.1G    ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1  
  4. 1.2G    ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1  
  5. 1.2G    ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1  
  6. 1.5G    ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1  
  7. 1.1G    ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1  
  8. 1.3G    ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1  
  9. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1  
  10. 1004M   ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1  
  11. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1  
  12. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1  
  13. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1  
  14. 2.6G    ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1  
  15. 1.8G    ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1  
  16. 4.1G    ./oradata/epps/invsubmat_d08.dbf  
  17. 4.0G    ./oradata/epps/gmtinv_d08.dbf  
  18. 4.1G    ./oradata/epps/gmtinv_x01.dbf  
  19. 8.1G    ./oradata/epps/undotbs02.dbf  
  20. 4.1G    ./oradata/epps/gmtinv_d07.dbf  
  21. 8.1G    ./oradata/epps/undotbs01.dbf  
  22. 4.1G    ./oradata/epps/gmtinv_x02.dbf  

如果你还需要对查找结果按照文件大小做一个排序,那么可以使用下面命令:

C#代码
  1. [root@getlnx01 u03]# find . -type f -size +800M  -print0 | xargs -0 du -h | sort -nr  
  2. 1004M   ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1  
  3. 8.1G    ./oradata/epps/undotbs02.dbf  
  4. 8.1G    ./oradata/epps/undotbs01.dbf  
  5. 4.1G    ./oradata/epps/invsubmat_d08.dbf  
  6. 4.1G    ./oradata/epps/gmtinv_x02.dbf  
  7. 4.1G    ./oradata/epps/gmtinv_x01.dbf  
  8. 4.1G    ./oradata/epps/gmtinv_d07.dbf  
  9. 4.0G    ./oradata/epps/gmtinv_d08.dbf  
  10. 2.6G    ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1  
  11. 1.8G    ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1  
  12. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1  
  13. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1  
  14. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1  
  15. 1.6G    ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1  
  16. 1.5G    ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1  
  17. 1.3G    ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1  
  18. 1.3G    ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1  
  19. 1.2G    ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1  
  20. 1.2G    ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1  
  21. 1.1G    ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1  
  22. 1.1G    ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1  

不过如上截图所示,有时候排列的顺序并不完全是按大小一致,这个是因为du命令的参数h所致,你可以统一使用使用MB来显示,这样就能解决这个问题。到这里,这个在Linux系统查找大文件的命令已经非常完美了,当然如果你还有很多的需求,那么可以在这个命令上做修改、调整.

2: 如何查找Linux下的大目录

 

譬如有时候磁盘空间告警了,而你平时又疏于管理、监控文件的增长,那么我需要快速的了解哪些目录变得比较大,那么此时我们可以借助du命令来帮我们解决这个问题。

C#代码
  1. [root@getlnx01 u03]# du -h --max-depth=1  
  2. 16K     ./lost+found  
  3. 33G     ./flash_recovery_area  
  4. 37G     ./oradata  
  5. 70G     .  

如果你想知道flash_recovery_area目录下面有哪些大文件夹,那么可以将参数max-depth=2 ,如果你想对搜索出来的结果进行排序,那么可以借助于sort命令。如下所示

C#代码
  1. [root@getlnx01 u03]# du -h --max-depth=2 | sort -n  
  2. 3.5G    ./flash_recovery_area/EPPS  
  3. 16K     ./lost+found  
  4. 29G     ./flash_recovery_area/backup  
  5. 33G     ./flash_recovery_area  
  6. 37G     ./oradata  
  7. 37G     ./oradata/epps  
  8. 70G     .  
  9. [root@getlnx01 u03]# du -hm --max-depth=2 | sort -n  
  10. 1       ./lost+found  
  11. 3527    ./flash_recovery_area/EPPS  
  12. 29544   ./flash_recovery_area/backup  
  13. 33070   ./flash_recovery_area  
  14. 37705   ./oradata  
  15. 37705   ./oradata/epps  
  16. 70775   .  

[root@getlnx01 u03]# cd /

[root@getlnx01 /]# du -hm --max-depth=2 | sort -n

 

有时候搜索出来的结果太多了(譬如,我从根目录开始搜索),一直在刷屏,如果我只想查出最大的12个文件夹,怎么办呢?此时就要借助head命令来显示了

C#代码
  1. [root@getlnx01 /]# du -hm --max-depth=2 | sort -nr | head -12  
  2. 407480  .  
  3. 167880  ./u04  
  4. 158685  ./u02/oradata  
  5. 158685  ./u02  
  6. 152118  ./u04/oradata  
  7. 70775   ./u03  
  8. 37705   ./u03/oradata  
  9. 33070   ./u03/flash_recovery_area  
  10. 5995    ./u01/app  
  11. 5995    ./u01  
  12. 3551    ./usr  
  13. 1558    ./usr/share  
  14. [root@getlnx01 /]#   

查看具体目录:du -sh  /www/cnmo/

查看整体概况:df -h

Linux/Unix | 评论(0) | 引用(0) | 阅读(2802)