Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I start bash on Cygwin and type:

dd if=/dev/zero | cat /dev/null

It finishes instantly. When I type:

dd if=/dev/zero > /dev/null

it runs as expected and I can issue

killall -USR1 dd

to see the progress. Why does the former invocation finishes instantly? Is it the same on a Linux box?

* Explanation why I asked such stupid question and possibly not so stupid question

I was compressing hdd images and some were compressed incorrectly. I ended up with the following script showing the problem:

while sleep 1 ; do killall -v -USR1 dd ; done &
dd if=/dev/zero bs=5000000 count=200 | gzip -c | gzip -cd |  wc -c

Wc should write 1000000000 at the end. The problem is that it does not on my machine:

bash-3.2$ dd if=/dev/zero bs=5000000 count=200 | gzip -c | gzip -cd |  wc -c
13+0 records in
12+0 records out
60000000 bytes (60 MB) copied, 0.834 s, 71.9 MB/s
27+0 records in
26+0 records out
130000000 bytes (130 MB) copied, 1.822 s, 71.4 MB/s
200+0 records in
200+0 records out
1000000000 bytes (1.0 GB) copied, 13.231 s, 75.6 MB/s
1005856128

Is it a bug or am I doing something wrong once again?

share|improve this question
5  
Ah, a nomination for the UUOC award; partmaps.org/era/unix/award.html –  Tom O'Connor Dec 23 '10 at 10:13
    
Thanks guys - from time to time everybody makes a mistake :) And thanks for the award :) –  agsamek Dec 23 '10 at 13:27
add comment

4 Answers 4

up vote 3 down vote accepted

I can't think of any reason to do what you are trying to do but the following way is the one you are looking for i guess.

 dd if=/dev/zero | cat > /dev/null
share|improve this answer
add comment

AFAIK, you first command is not functionnal. You are trying to pipe the output of /dev/zero into a command that takes no input.

cat /dev/null is just a command that outputs nothing. Piping anything something in it will therefore do nothing at all.

When you use the stdout redirect, the output of /dev/zero gets written to the file in question (/dev/null therefore nowhere).

share|improve this answer
add comment

What dd if=/dev/zero | cat /dev/null does is:

run cat /dev/null attach it's stdin to dd stdout. Problem is, that /dev/null is empty. So cat does what is asked to do: open empty file write it contents to stdout and finish.

cat does pipe output from stdin only when there are no files specified. cat /dev/null - will pipe contents of /dev/null and stdin to stdout.

As such dd if=/dev/zero | cat /dev/null apart from wasting a process differs in nothing from cat /dev/null.

share|improve this answer
add comment

I tried it on Cygwin and Ubuntu and got the correct result in Ubuntu. If I don't send a signal to dd it works on Cygwin. I'm going to say that's a bug.

When I did a tee to send the output to a file, it consisted of all zero bytes, but there were too many of them.

dd if=/dev/zero bs=5000000 count=200 | gzip -c | gzip -cd |  tee dd.out | wc -c
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.