I have an irritating problem: redirecting stderr does not work. I get:

iptables: Chain already exists

I can't be bothered to check if a chain exists already (pointless, iptables just throws an error if the chain exists before I flush it in the next step, so why bother checking if it already exists). In order to ignore this, I redirect stderr to /dev/null but this does not seem to work.

In general: how do I:

  1. check which stream is used by a command in bash? is this even possible?

  2. redirect ALL streams output by a command?

  • 1
    Yikes! layman error: i was redirecting stderr before redirecting stdout: iptables -N droplist 2>&1 >/dev/null iptables: Chain already exists iptables uses stderr on error, "iptables -N droplist >/dev/null 2>&1" works. Nevertheless, the questions still stand I think. – LetMeSOThat4U Jul 8 '13 at 10:42
  • You might be interested in "netstat -tnlp" – Synthead Jul 24 '13 at 19:45
  • what is your iptables command?

  • you can look at /proc/<pid>/fd/ ! there are "pipe" entries with a pid of another command involved in the command chain

  • redirecting all streams in bash according to TFM:

    There are two formats for redirecting standard output and standard error:
    Of the two forms, the first is preferred. This is semantically equivalent to
    >word 2>&1

Stefan K.

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.