_php instance of the MD5 method of recursively generating a file in a directory of Linux systems

Source: Internet
Author: User
MD5 using md5sum recursively to generate the entire directory under Linux
Today to use md5sum operation directory, recursively generate all the files in the directory MD5 value, the results found that it does not support recursive operation and then wrote a PHP script to deal with
Code:

  <?php $path = '/data/www/bbs/source ';    $outfile = ' file.md5 ';       GET_FILE_MD5 ($path, $outfile);      function Get_file_md5 ($path, $outfile) {$path = RTrim ($path, '/');        if (function_exists (' Scandir ')) {$files = Scandir ($path);          foreach ($files as $v) {if ($v! = '. ' && $v! = ') {$file = $path. '            /'. $v;            if (Is_dir ($file)) {get_file_md5 ($file, $outfile); }else {file_put_contents ($outfile, Md5_file ($file). " ". $file."            \ n ", file_append);        }}}}else {$files = Opendir ($path);            while (($f = Readdir ($files))!== false) {if ($f = = '. ' | | $f = = ' ... ')          Continue $file = $path. '          /'. $f;          if (Is_dir ($file)) {get_file_md5 ($file, $outfile); }else {file_put_contents ($outfile, Md5_file ($file). " ". $file." \ n ", FILE_append);      }} closedir ($files);  }    }

Note: The resulting MD5 value and the file are two spaces, otherwise the error is as follows

Copy the Code code as follows: Md5sum:file1.md5:no properly formatted MD5 checksum lines found

In a simpler way, use the Linux Find command to get the word done.
Code:

  

Test

  Md5sum-c file1.md5   md5sum-c file2.md5  


This will output all the test results to the screen, if the last one shows such information md5sum:warning:2 of 1147 computed checksums did not match then indicates that there are 2 non-conforming in a total of 1147 articles
Then we can

  

It's easy to know which files have been tampered with.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.