How to redirect output from dd command to /dev/null?

webminal.org picture webminal.org · Apr 7, 2010 · Viewed 9.9k times · Source

In shell script i need to redirect output from dd command to /dev/null - how to do that?

( dd if=/dev/zero of=1.txt count=1 ) 2>&1 /dev/null

didn't work!

Answer

pixelbeat picture pixelbeat · Apr 7, 2010

No need for a subshell.

dd if=/dev/zero of=1.txt count=1 2>/dev/null

However what if there is an error? You could instead do:

err=$(dd if=/dev/zero of=1.txt count=1 2>&1) || echo "$err" >&2