开发者

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

开发者 https://www.devze.com 2022-12-25 17:43 出处:网络
In shell script i nee开发者_运维技巧d to redirect output from dd commandto /dev/null - how to do that?

In shell script i nee开发者_运维技巧d 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!


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号