Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question is probably quite easy but I don't know how to accomplish this.

I want to verify a file using md5sum -c file.md5. I can do that by hand, but I don't know how to check the validity in a script. I hope you could help me?

share|improve this question
up vote 13 down vote accepted

You can use md5sum's return status:

if md5sum -c file.md5; then
    # The MD5 sum matched
else
    # The MD5 sum didn't match
fi

To make things cleaner, you can add --status to tell md5sum (perhaps GNU's version only) to be silent:

if md5sum --status -c file.md5; then
    # The MD5 sum matched
else
    # The MD5 sum didn't match
fi

Shorter forms work just as well if appropriate:

md5sum --status -c file.md5 && echo OK
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.