Bash

如何抑制 dd 輸出?

  • October 9, 2019

我有一個 bash 腳本,它使用dd. 問題是 dd 會拋出大量輸出,這會干擾我的腳本輸出。環顧四周,我找到了解決方案:

dd if=boot1h of="/dev/r$temp1" >& /dev/null

是否有替代方案,或者重定向到/dev/null唯一的方式?

dd(1)手冊頁:

  status=noxfer
         suppress transfer statistics

因此:

dd if=boot1h of="/dev/r$temp1" status=noxfer

這仍然輸出

0+1 records in
0+1 records out

退出時垃圾dd,因此重定向到數據接收器確實是您唯一的選擇。

添加status=none

dd if=boot1h of="/dev/r$temp1" status=none

來自dd (coreutils) 8.21 文件

'status=LEVEL'
     Transfer information is normally output to stderr upon receipt of
     the 'INFO' signal or when 'dd' exits.  Specifying LEVEL will adjust
     the amount of information printed, with the last LEVEL specified
     taking precedence.

     'none'
          Do not print any informational or warning messages to stderr.
          Error messages are output as normal.

     'noxfer'
          Do not print the final transfer rate and volume statistics
          that normally make up the last status line.

     'progress'
          Print the transfer rate and volume statistics on stderr, when
          processing each input block.  Statistics are output on a
          single line at most once every second, but updates can be
          delayed when waiting on I/O.

引用自:https://unix.stackexchange.com/questions/6699