GNU coreutils の dd に プログレスオプションがあった

dd の進捗は SIGUSR1 を投げると覚えていたのですが,man を眺めていると status=progress というオプションがあるのに気づきました.

manより
status=LEVEL
       The LEVEL of information to print to stderr; 'none' suppresses
       everything but error messages, 'noxfer' suppresses  the  final
       transfer  statistics,  'progress' shows periodic transfer sta‐
       tistics

2015-07-03 の GNU coreutils 8.24 で入ったようです.

dd accepts a new status=progress level to print data transfer statistics
on stderr approximately every second.

これまでも独自パッチでddにプログレスを出すようにするものなどはありましたがGNU ddに導入されていたんですね.気づきませんでした.

てことで試してみます.まずは従来の方法から.

dd開始
$ dd if=/dev/urandom of=/dev/null count=99999 &
[1] 19386
killコマンドで USER1 シグナルを投げる
$ kill -USR1 19522
2294+0 レコード入力
2293+0 レコード出力
2404384768 bytes (2.4 GB, 2.2 GiB) copied, 11.0258 s, 218 MB/s
killallコマンドでpidではなくプロセス名を指定
$ killall -USR1 dd
15648+1 レコード入力
15647+1 レコード出力
16407664896 bytes (16 GB, 15 GiB) copied, 76.1063 s, 216 MB/s

※pkillを使うと部分一致になるので意図しないプロセスにシグナルを送ってしまうことがあるので注意

$ pgrep dd
2
70
3937
$ ps 2 70 3937
  PID TTY      STAT   TIME COMMAND
    2 ?        S      0:00 [kthreadd]
   70 ?        I<     0:00 [ipv6_addrconf]
 3937 pts/9    R      0:13 dd if=/dev/urandom of=/dev/null bs=1M count=99999
watchコマンドで定期的に実行
$ watch killall -USR1 dd
98448+3 レコード入力
98447+3 レコード出力
103231407040 bytes (103 GB, 96 GiB) copied, 487.072 s, 212 MB/s
 :
ddコマンド実行時にpvコマンドを挟む
$ cat /dev/urandom | pv | dd of=/dev/null bs=1M count=99999
1.06GiB 0:00:06 [ 182MiB/s] [     <=>                                        ]
pvコマンドでファイル出力
$ pv /dev/urandom | dd of=/dev/null bs=1M count=99999
 502MiB 0:00:03 [ 170MiB/s] [  <=>                                           ]
ddの status=progress オプションを利用
$ dd if=/dev/urandom of=/dev/null bs=1M count=99999 status=progress
1910505472 bytes (1.9 GB, 1.8 GiB) copied, 9 s, 212 MB/s

流石に純正だけあっていい感じですね.問題はいざ使うときに思い出せるかという…….pvが覚えやすくて便利なんですよね.

そもそもdd使わずGNU ddrescue を使う?まあ大抵の用途ではそっちのほうが良いかもです.

試した環境
$ dd --version
dd (coreutils) 8.28
Copyright (C) 2017 Free Software Foundation, Inc.
ライセンス GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

作者 Paul Rubin、 David MacKenzie、および Stuart Kemp。
$ dpkg-query -W coreutils
coreutils       8.28-1
pv      1.6.6-1
$ lsb_release -d
Description:    Debian GNU/Linux unstable (sid)
$ uname -m
x86_64

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です