为什么 dd 没有输出到 stdout?

为什么 dd 没有输出到 stdout?

这是我遇到问题的命令

username@computer /current/working/directory
$ dd if="$filename" bs=1 seek=10 count=10 conv=notrunc status=progress^C
0+0 records in
0+0 records out
0 bytes copied, 1.70242 s, 0.0 kB/s

测试输出至文件试用(为了理智?)

username@computer /current/working/directory
$ dd if="$filename" bs=1 seek=10 count=10 conv=notrunc status=progress of=test
22+0 records in
22+0 records out
22 bytes copied, 0.0115305 s, 1.9 kB/s

环境

username@computer  /current/working/directory
$ echo $filename
somefile.ext

username@computer /current/working/directory
$ dd --version
dd (coreutils) 8.26
Packaged by Cygwin (8.26-1)
Copyright (C) 2016 Free Software Foundation, Inc.
License 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.

Written by Paul Rubin, David MacKenzie, and Stuart Kemp.

username@computer /current/working/directory
$ echo $SHELL
/bin/bash

username@computer /current/working/directory
$ bash --version
GNU bash, version 4.4.5(1)-release (x86_64-unknown-cygwin)
Copyright (C) 2016 Free Software Foundation, Inc.
License 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.

username@computer /current/working/directory
$ stty
speed 38400 baud; line = 0;
start = <undef>; stop = <undef>; lnext = ^Q;
-imaxbel
-echoe -echok -echoctl -echoke

Man 页中的相关部分dd似乎暗示输出到 stdout 文件描述符/流是默认行为:

      of=FILE
             write to FILE instead of stdout

我在这个链接中发现的例子也暗示:AskUbuntu - 如何监控 dd 的进度?

  • Windows 10 专业版 x64
  • 赛格威
  • 康埃穆 170517

答案1

问题可能在于seek跳过dd某些块在输出开始时。你希望它如何工作stdout?在我的 Ubuntu 中,类似的dd命令也会挂起,直到我按下Ctrl+ C

解决方案:去掉该seek=10选项它就应该可以工作了。

注意:要跳过输入,请使用skip。也许这就是你真正想要的。

答案2

该行末尾有“of=test”字样,告诉 dd 将输出写入文件“test” - 删除该位,它将写入标准输出。

相关内容