Shell – md5sum check (no file)

hashsumshell-script

So I'm trying to check dozens of files using a shell script. The file check happens at different times.

Is there a way to do this?

md5sum -c 24f4ce42e0bc39ddf7b7e879a File.name

or even better sha512sum

sha512sum -c 24f4ce42e0bc39ddf7b7e879a File.name

Right now I have to do this:

md5sum -c file.md5sums File.name

Or better yet I could have all the md5sums in a single file and check them like this:

md5sum -c `sed 1p file.md5sums` File.name
md5sum -c `sed 2p file.md5sums` File.name
md5sum -c `sed 3p file.md5sums` File.name
md5sum -c `sed 4p file.md5sums` File.name

It just seems silly to have dozens of files with single entries in them.

Best Answer

If you're doing this in a script then you can just do a simple comparison check e.g.

if [ "$(md5sum < File.name)" = "24f4ce42e0bc39ddf7b7e879a  -" ]
then
  echo Pass
else
  echo Fail
fi

Note the extra spaces and - needed to match the output from md5sum.

You can make this a one-liner if it looks cleaner

[[ "$(md5sum < File.name)" = "24f4ce42e0bc39ddf7b7e879a  -" ]] && echo Pass || echo Fail
Related Question