Skip to main content

Linux如何查找大文件或目录总结

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

[root@getlnx01 u03]# pwd
/u03
[root@getlnx01 u03]# 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
./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
./oradata/epps/invsubmat_d08.dbf
./oradata/epps/gmtinv_d08.dbf
./oradata/epps/gmtinv_x01.dbf
./oradata/epps/undotbs02.dbf
./oradata/epps/gmtinv_d07.dbf
./oradata/epps/undotbs01.dbf
./oradata/epps/gmtinv_x02.dbf

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

root@getlnx01 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 ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
-rw-r----- 1 oracle oinstall 1368244224 Mar 6 12:02 ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
-rw-r----- 1 oracle oinstall 1629069312 Mar 6 12:04 ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
-rw-r----- 1 oracle oinstall 1629954048 Mar 6 12:06 ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
-rw-r----- 1 oracle oinstall 1202192384 Mar 6 12:07 ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
-rw-r----- 1 oracle oinstall 1189388288 Mar 6 12:10 ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
-rw-r----- 1 oracle oinstall 1089257472 Mar 6 12:11 ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1
-rw-r----- 1 oracle oinstall 1097687040 Mar 6 12:12 ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
-rw-r----- 1 oracle oinstall 1051009024 Mar 6 12:13 ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
-rw-r----- 1 oracle oinstall 4294975488 Apr 3 15:07 ./oradata/epps/gmtinv_d07.dbf
-rw-r----- 1 oracle oinstall 4194312192 Apr 1 22:36 ./oradata/epps/gmtinv_d08.dbf
-rw-r----- 1 oracle oinstall 4294975488 Apr 3 15:54 ./oradata/epps/gmtinv_x01.dbf
-rw-r----- 1 oracle oinstall 4294975488 Apr 3 15:57 ./oradata/epps/gmtinv_x02.dbf
-rw-r----- 1 oracle oinstall 4294975488 Apr 1 22:35 ./oradata/epps/invsubmat_d08.dbf
-rw-r----- 1 oracle oinstall 8589942784 Apr 4 09:55 ./oradata/epps/undotbs01.dbf
-rw-r----- 1 oracle oinstall 8589942784 Apr 4 09:15 ./oradata/epps/undotbs02.dbf

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

[root@getlnx01 u03]# 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
1.3G ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
1004M ./flash_recovery_area/backup/backupsets/ora_df873524162_s46823_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
2.6G ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
1.8G ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
4.1G ./oradata/epps/invsubmat_d08.dbf
4.0G ./oradata/epps/gmtinv_d08.dbf
4.1G ./oradata/epps/gmtinv_x01.dbf
8.1G ./oradata/epps/undotbs02.dbf
4.1G ./oradata/epps/gmtinv_d07.dbf
8.1G ./oradata/epps/undotbs01.dbf
4.1G ./oradata/epps/gmtinv_x02.dbf


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

[root@getlnx01 u03]# 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
2.6G ./flash_recovery_area/backup/backupsets/ora_df873513413_s46809_s1
1.8G ./flash_recovery_area/backup/backupsets/ora_df873514789_s46810_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873520789_s46817_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873519953_s46816_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873518302_s46814_s1
1.6G ./flash_recovery_area/backup/backupsets/ora_df873516500_s46812_s1
1.5G ./flash_recovery_area/backup/backupsets/ora_df873517396_s46813_s1
1.3G ./flash_recovery_area/backup/backupsets/ora_df873519197_s46815_s1
1.3G ./flash_recovery_area/backup/backupsets/ora_df873515765_s46811_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873522876_s46820_s1
1.2G ./flash_recovery_area/backup/backupsets/ora_df873521714_s46818_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523646_s46822_s1
1.1G ./flash_recovery_area/backup/backupsets/ora_df873523321_s46821_s1

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

[root@getlnx01 u03]# du -h --max-depth=1
16K ./lost+found
33G ./flash_recovery_area
37G ./oradata
70G .

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

[root@getlnx01 u03]# du -h --max-depth=2 | sort -n
3.5G ./flash_recovery_area/EPPS
16K ./lost+found
29G ./flash_recovery_area/backup
33G ./flash_recovery_area
37G ./oradata
37G ./oradata/epps
70G .

参考资料
http://www.cnblogs.com/kerrycode/p/4391859.html

wordpress wp-includes/http.php漏洞修复

在wp-includes/http.php中有一处检验规则漏洞,文件中的wp_http_validate_url函数对输入IP验证不当,导致黑客可构造类似于012.10.10.10这样的畸形IP绕过验证,进行SSRF。

源代码的第534行中,调用了preg_match方法对传入的IP地址进行校验,这里可以构造一个畸形的IP地址,以跳过if去执行else,从而使用了gethostbyname。

核心问题出在此正则表达式的校验比较弱,正确的IPv4地址是xxx.xxx.xxx.xxx,但是首位不能是0。

 

解决办法-:增强正则表达式。

^(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))$

function wp_http_validate_url( $url ) {
 509      $original_url = $url;
 510      $url = wp_kses_bad_protocol( $url, array( 'http', 'https' ) );
 511      if ( ! $url || strtolower( $url ) !== strtolower( $original_url ) )
 512          return false;
 513  
 514      $parsed_url = @parse_url( $url );
 515      if ( ! $parsed_url || empty( $parsed_url['host'] ) )
 516          return false;
 517  
 518      if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) )
 519          return false;
 520  
 521      if ( false !== strpbrk( $parsed_url['host'], ':#?[]' ) )
 522          return false;
 523  
 524      $parsed_home = @parse_url( get_option( 'home' ) );
 525  
 526      if ( isset( $parsed_home['host'] ) ) {
 527          $same_host = ( strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] ) || 'localhost' === strtolower( $parsed_url['host'] ) );
 528      } else {
 529          $same_host = false;
 530      }
 531  
 532      if ( ! $same_host ) {
 533          $host = trim( $parsed_url['host'], '.' );
 534          if ( preg_match( '#^(([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)\.){3}([1-9]?\d|1\d\d|25[0-5]|2[0-4]\d)$#', $host ) ) {
 535              $ip = $host;
 536          } else {
 537              $ip = gethostbyname( $host );
 538              if ( $ip === $host ) // Error condition for gethostbyname()
 539                  $ip = false;
 540          }
 541          if ( $ip ) {
 542              $parts = array_map( 'intval', explode( '.', $ip ) );
 543              if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
 544                  || ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
 545                  || ( 192 === $parts[0] && 168 === $parts[1] )
 546              ) {
 547                  // If host appears local, reject unless specifically allowed.
 548                  /**
 549                   * Check if HTTP request is external or not.
 550                   *
 551                   * Allows to change and allow external requests for the HTTP request.
 552                   *
 553                   * @since 3.6.0
 554                   *
 555                   * @param bool   false Whether HTTP request is external or not.
 556                   * @param string $host IP of the requested host.
 557                   * @param string $url  URL of the requested host.
 558                   */
 559                  if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) )
 560                      return false;
 561              }
 562          }
 563      }
 564  
 565      if ( empty( $parsed_url['port'] ) )
 566          return $url;
 567  
 568      $port = $parsed_url['port'];
 569      if ( 80 === $port || 443 === $port || 8080 === $port )
 570          return $url;
 571  
 572      if ( $parsed_home && $same_host && isset( $parsed_home['port'] ) && $parsed_home['port'] === $port )
 573          return $url;
 574  
 575      return false;
 576  }