I expected this:

nc -l localhost 7000 </dev/null &
nc localhost 7000 </etc/profile

and this

nc -l localhost 7000 </etc/profile &
nc localhost 7000 </dev/null

to finish after printing my /etc/profile but both command groups end up getting stuck (both processes in the first case; in the second case, the server finishes but the client does not).

Why don't the commands finish?

Is this a bug in my nc/Linux (4.15)? I tried it on MacOS and Cygwin and only the Linux commands aren't finishing.


I'm using netcat and not gnu-netcat; I'm not sure what version you're using, but if it's gnu-netcat the options might be different.

I have a -q option:

-q seconds after EOF is detected, wait the specified number of seconds then quit

So, if I do:

$ nc -l localhost -p 7000 -q 0 < /etc/passwd

Followed by:

$ nc localhost 7000

Then I get the content of /etc/passwd on the second terminal, and both instances of nc terminate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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