Issue
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.
Solution
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.
Answered By - mjuarez