0

If I have a file named file1. And I then make an md5 file for file1, I then change the contents of file1, so the md5 is different. When I run a checksum on it, I will get

/home/student/.trashCan/file1: FAILED.

This is what I want, however i also get

md5sum: WARNING: 1 computed checksum did NOT match

How would i suppress this warning? So that i can get output from:

/home/student/.trashCan/file1: FAILED

/home/student/.trashCan/file2: OK

md5sum: WARNING: 1 computed checksum did NOT match

$student@osboxes

To this:

/home/student/.trashCan/file1: FAILED

/home/student/.trashCan/file2: OK

$student@osboxes

If i use the --status flag, it will supress the warning but also the output. And if i use grep/awk/cut then i get my output, but i also get the warning.

Community
  • 1
  • 1
Amelia Magee
  • 452
  • 5
  • 14

1 Answers1

4

The problem is that the output from md5sum is two parts:

$ md5sum --check test.txt.md5 
test.txt: FAILED
md5sum: WARNING: 1 computed checksum did NOT match

The first test.txt: FAILED line is sent to standard output. However, the second line, that starts with md5sum is sent to standard error. So, you can fix this by issuing your command this way:

$ md5sum --check test.txt.md5 2>/dev/null
test.txt: FAILED

This works because you're specifically telling it to send stderr to /dev/null. stdout will still be displayed correctly.

mjuarez
  • 16,372
  • 11
  • 56
  • 73
  • You are an absolute star!! <3 I've been frying my brain out trying different methods of the --status flag and if statements. I knew about /dev/null but I had no idea that there are different classifications of messages you can send to the terminal. Thanks so much!!~ – Amelia Magee Oct 24 '18 at 02:00