Per the man page, using dd status=none
won't get rid of error messages.
If there is a single error message that is expected/desirable, you can use grep
to both check that execution was as expected and eat the output. In this example, I obliterate a partition by overwriting with zeros so that mke2fs
won't question the need to reformat it.
Running dd
without a count
specifier will always result in a "No space left on device" error message and nonzero exit value. By searching for the expected error message with grep
, the expected behavior returns no error while any unexpected behavior returns an error.
# desired behavior: erase to the end of partition and return zero as exit code.
$ dd if=/dev/zero of=/dev/mmcblk2p7 bs=1M 2>&1 | grep -q 'No space left on device'
$ echo $?
0
Nonzero exit code is returned if our expected error message doesn't appear.
$ dd if=/dev/zero of=/dev/mmcblk2p7 bs=1M 2>&1 | grep -q 'Frobulators are not block-aligned'
$ echo $?
1
The redirect of stderr
to stdout
is necessary because most dd
output goes to stderr
while grep
operates on stdout
. Use grep's -q
flag to control visibility of the output.
/dev/null
-- you're sudoing becausedd
needs write access to/dev/r$temp1
(I assume). You're going to need to do that no matter how you suppressdd
's output; redirecting output to/dev/null
doesn't require root – Michael Mrozek Jan 31 '11 at 17:40cat
,head
ortail
instead. – Gilles 'SO- stop being evil' Jan 31 '11 at 19:46