According to this article, by replacing:
$ dd if=/dev/sda of=/dev/sdb [additional options]
with:
$ pv -tpreb /dev/sda | dd of=/dev/sdb [additional options]
one can augment the default dd
behaviour by displaying a progress bar, similar to that in wget
. This works well when I can remember to use it, so I thought aliasing the first command to the second was the logical next step.
After some research, it would appear a simple alias
in .bash_rc
can't accomplish this. Could someone provide a BASH function to capture the if=...
and work it into the resultant command?
2 Answers 2
Aliases are only suitable to give a command a shorter name or give it extra arguments. For anything else, use a function. See Aliases vs functions vs scripts for more details.
pvdd () {
pv -tpreb "1ドル" | dd of="2ドル"
}
pvdd /dev/sda /dev/sdb
However, do not use this function. dd if=foo of=bar
is equivalent to cat <foo >bar
, only
- slower, and worse,
- unreliable in certain circumstances, especially when reading or writing to a pipe.
The use of dd
as a low-level command to access disks is a myth1. The magic comes from the /dev
entries, not from dd
.
So the command you want is simply
pv -tpreb /dev/sda >/dev/sdb
and you can make an alias for dd -tpreb
if you like.
1 There is a historical origin to this myth: when accessing tapes, the control over block size that dd
provides is sometimes necessary. But for everything else, imposing a block size the way dd
does it can lead to data loss.
Your question isn't terribly clear, but it appears that you need a shell function. You could create a function mydd
:
mydd() { pv -tpreb /dev/sda | dd "$@"; }
and invoke it by saying:
mydd of=/dev/sdb [additional options]
and the executed command would be:
pv -tpreb /dev/sda | dd of=/dev/sdb [additional options]
-
Thanks for this. It's pretty close to where I need it, except
/dev/sda
should be a variable. Is it possible to make the shell function executepv -tpreb [source] | dd of=[dest] [optional additional options]
fromdd if=[source] of=[dest] [optional additional options]
? Thanks!James Fu– James Fu2014年03月12日 07:15:59 +00:00Commented Mar 12, 2014 at 7:15
You must log in to answer this question.
Explore related questions
See similar questions with these tags.
pv < /dev/sda > /dev/sdb
. Beware of the implications of usingdd
with pipes.dd
useUSR1
signal to display progress statistics.