Find the answer to your Linux question:
Results 1 to 2 of 2
I would like to compare two md5sum outputs to see if the files match. in my script I have Code: ORG_FILE="/path/to/org/file.zip" NEW_FILE="path/to/new/file.zip" MD5_ORIG=$(md5sum -b "$ORG_FILE") MD5_NEW=$(md5sum -b "$NEW_FILE") this gives ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! pendal's Avatar
    Join Date
    Jan 2008
    Posts
    15

    BASH md5sum compare


    I would like to compare two md5sum outputs to see if the files match.

    in my script I have

    Code:
    ORG_FILE="/path/to/org/file.zip"
    NEW_FILE="path/to/new/file.zip"
    
    MD5_ORIG=$(md5sum -b "$ORG_FILE")
    MD5_NEW=$(md5sum -b "$NEW_FILE")
    this gives me lines like
    MD5_ORIG='dd3e19b2d1ec5f9b459238842ef560c7 */path/to/org/file.zip'
    MD5_NEW='dd3e19b2d1ec5f9b459238842ef560c7 */path/to/new/file.zip'

    How do I get just the MD5 hash and not the */.... stuff so I can compare them.

    i tried
    Code:
    JUST_HASH=${$MD5_ORIG:0:32}
    but All I get is

    dir_mon_notify.sh: line 79: ${$MD5_ORIG:0:32}: bad substitution


    Thanks for any help.

    C

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,382
    This might do
    Code:
    diff <(md5sum /path/to/org/file.zip| awk '{print $1}') <(md5sum path/to/new/file.zip | awk '{print $1}')
    Note:
    If either old or new file stays static, you only need to compute the md5sum once and save it into a file.
    md5sum can then use that file to compare against a new run.
    You must always face the curtain with a bow.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •