md5sum check (no file)

I was able to do a sha256sum on multiple file, write the output to a text file and run a sha256sum -c sumfile and it seemed to work for me.

$ sha256sum $(find /etc/ -maxdepth 1 -type f) > test.txt
$ sha256sum -c test.txt
/etc/statetab: OK
/etc/sysctl.conf: OK
/etc/system-release: OK
/etc/system-release-cpe: OK
/etc/termcap: OK
/etc/updatedb.conf: OK
/etc/vconsole.conf: OK
/etc/vimrc: OK
/etc/virc: OK
/etc/yum.conf: OK
$ sha256sum --version
sha256sum (GNU coreutils) 8.22

The md5sum utility, as all the other similar utilities in the GNU coreutils collection, is able to take a file of checksums and verify these against the corresponding files in the filesystem.

Let's say I've generated the checksum file like this:

$ md5sum /etc/* >sums
$ cat sums
e55afe6e88abb09f0bee39549f1dfbbd  /etc/afpovertcp.cfg
279f7ab7d2609163e5034738b169238b  /etc/aliases
5c1ba75b6d9d8cf921ec83e2a54c9bb5  /etc/asl.conf
d41d8cd98f00b204e9800998ecf8427e  /etc/xtab
32d37eb59a7c3735635db329adad86d7  /etc/zprofile
4efb8dbeb8f46ca3879666b313a2607f  /etc/zshrc

I can then verify all those checksums in one go, like this:

$ md5sum -c sums
/etc/afpovertcp.cfg: OK
/etc/aliases: OK
/etc/asl.conf: OK
/etc/xtab: OK
/etc/zprofile: OK
/etc/zshrc: OK

If I misunderstood you and you just want to check one particular file out of several in your sums file, then I'd do like this:

$ fgrep "/etc/xtab" sums | md5sum -c -

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

if [ "$(md5sum <" = "24f4ce42e0bc39ddf7b7e879a  -" ]
  echo Pass
  echo Fail

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

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

[[ "$(md5sum <" = "24f4ce42e0bc39ddf7b7e879a  -" ]] && echo Pass || echo Fail