【Linux运维】如何查找大文件或大目录
【Linux运维】如何查找大文件或大目录
目录
一、如何查找大文件
case1: 查找当前系统中有哪儿文件的大小超过800MB
[root@test /]#find . -type f -size +800M
./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1
./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
case2: 查找当前系统中有哪儿文件的大小超过800MB,并且向看下文件的其他属性
[root@test u03]# find . -type f -size +800M -print0 | xargs -0 ls -l
-rw-r----- 1 oracle oinstall 2782846976 Mar 6 11:51 ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
-rw-r----- 1 oracle oinstall 1878433792 Mar 6 11:53 ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
-rw-r----- 1 oracle oinstall 1378492416 Mar 6 11:54 ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
-rw-r----- 1 oracle oinstall 1641381888 Mar 6 11:56 ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
-rw-r----- 1 oracle oinstall 1564065792 Mar 6 11:58 ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
-rw-r----- 1 oracle oinstall 1663492096 Mar 6 12:00
case3:查找当前系统中有哪儿文件的大小超过800MB,并查看下文件的具体大小
[root@test /]# find . -type f -size +800M -print0 | xargs -0 du -h
1.3G ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
1.5G ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1
case4:查找当前系统中有哪些文件的大小超过800MB, 并查看文件的具体大小,并对结果做个排序
[root@test /]# find . -type f -size +800M -print0 | xargs -0 du -h | sort -nr
1004M ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
8.1G ./oradata/epps/undotbs02.dbf
8.1G ./oradata/epps/undotbs01.dbf
4.1G ./oradata/epps/invsubmat_d08.dbf
4.1G ./oradata/epps/gmtinv_x02.dbf
4.1G ./oradata/epps/gmtinv_x01.dbf
4.1G ./oradata/epps/gmtinv_d07.dbf
4.0G ./oradata/epps/gmtinv_d08.dbf
# 注意有时候,并不是按照大小排列的,由于du -h的原因,我们可以使用du -mh ,统一使用MB来显示文件大小。这样比较准确
二、如何查找Linux下的大目录
# 查找当前目录下的大目录,只查找一层
du -h --max-depth=1
# 查找当前目录下的大目录,只查找二层(当前目录包含的目录,和子目录)
du -h --max-depth=2 | sort -n
#只想查出最大的12个文件夹
du -hm --max-depth=2 | sort -nr | head -12