3 ms·
This article is full of Useless Uses of Cat[1] that could just use redirection operators. For instance, cat image.iso | pv >/dev/sdb could be rewritten as
by stirner 10y ago
This article is full of Useless Uses of Cat[1] that could just use redirection operators. For instance,
cat image.iso | pv >/dev/sdb
could be rewritten as
pv < image.iso > /dev/sdb
A related mistake is the Useless Use of Echo, since any command of the form
echo "foo" | bar
can be written using here strings as
bar <<< "foo"
or even
bar <<WORD
foo
WORD
[1] http://porkmail.org/era/unix/award.html http://porkmail.org/era/unix/award.html
- alayne 10y agoUseless or not, I personally prefer left to right flow.
- discreditable 10y agopv can read files directly and give more detailed progress. No stdin redirection is needed. pv image.iso >/dev/sdb
- j3097736 10y ago>pv < image.iso > /dev/sdb Huh? pv can cat stuff on it's own, and it will be able to make a progress bar based on the filesize pv image.img > /dev/sdb
- stirner 10y agoOkay. I don't actually use pv, so I was just extrapolating from the original post. In any case, cat is definitely the wrong choice.
- amelius 10y agoSo I suppose that the command pv < image.iso > /dev/sdb would actually need to buffer the complete file, before commencing to write to the device (and showing the progress), which would defeat the whole idea of showing progress.
- farhaven 10y agoIt wouldn't. It just won't be able to predict a file size.
- heinrich5991 10y agoIf `pv` doesn't know the input size, it doesn't show it. In your case, it can determine that its stdin is a file by looking at the `/proc/self/fd/0` symlink: $ ls -l /proc/self/fd/0 < /tmp/x lr-x------ 1 user users 64 <date> /proc/self/fd/0 -> /tmp/x
- stirner 10y agoFrom what I can tell, bash uses 4K buffers for pipelines.
- throwanem 10y agoThey could! They could be super annoying to read, too. Pipelines make more sense to humans when they always read in the same direction. In the rare case where the volume of data is large enough to make the efficiency hit noticeable on large machines, rewriting a pipeline to eliminate a leading cat makes sense. In all other cases, it is a premature and unnecessary optimization.
- yjftsjthsd-h 10y agoYeah, in BASH at least it's nicer to use <image.iso pv > /dev/sdb