Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a bash script, I'm using tools like conntrack and tcpdump to output results to a file, but wish to hide the standard message displayed on the first output line on the command line after executing the command/script.


conntrack v1.0.0 (conntrack-tools): 6 flow entries have been shown.

After reading the bash man page, I've tried things like:

conntrack -L|grep "dport=6439" &> /tmp/file

No matter what redirect option I try, the conntrack message stating the number of flow entries is always displayed in the shell where I execute the script. Same thing goes for tcpdump where it lists the capturing device and number of packets captured, etc.

Of course, I could add clear after the conntrack or tcpdump commands to quickly hide the output, but that solution is ugly.

How can I hide these kinds of messages?

share|improve this question
This can be useful for you too stackoverflow.com/a/549776/792066 – Braiam Jul 17 '13 at 0:08
side note: /dev/null would probably be better – strugee Jul 17 '13 at 0:25
/dev/null wouldn't apply here because I want to redirect the standard output to file /tmp/file/ – John B Jul 18 '13 at 0:08
up vote 6 down vote accepted

Those messages are printed as errors (stderr) rather than regular output (stdout).

Only stdout gets piped, not stderr. So by having &> /tmp/file after grep, you are only merging the stdout and stderr output of grep itself, it will not merge the stderr of conntrack

For your example, you probably want something like:

conntrack -L 2>&1 | grep "dport=6439" > /tmp/file

stderr is file descriptor 2, and stdout is file descriptor 1. 2>&1 merges stderr into stdout.

By sticking 2>&1 on conntrack, the output gets merged before it is piped to grep. There is no need to merge again on grep.

share|improve this answer

Your Answer


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.