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

10,204

Solution 1

If you want to redirect only the standard output of the command do:

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

and if you want to redirect both stdout and stderr to /dev/null do:

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

Solution 2

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
Share:
10,204
webminal.org
Author by

webminal.org

Free and Open Source programmer. Projects include: FileSystem Projects and Free Online Linux Terminal

Updated on June 16, 2022

Comments

  • webminal.org
    webminal.org almost 2 years

    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!