Linux – How to quieten tcpdump output when reading a pcap file

command linelinuxstderrstdouttcpdump

I notice that when using tcpdump to read a pcap file, the tcpdump command somehow manages to print information to my console even when I redirect both STDOUT and STDERR. How can I prevent tcpdump from printing "reading from file capture, link type EN10MB (Ethernet)" every time it runs?

For example, the following command prints a line when I expected none:

$ tcpdump -A -r capture.pcap | grep interesting-string > /dev/null 2>&1
reading from file capture.pcap, link-type EN10MB (Ethernet)

I would like to prevent that line from appearing because it adds unnecessary and unwanted noise to a script's output. I've checked the man page and did not see an option to prevent that message from appearing. I've searched the web for ways to suppress output not captured by STDOUT and STDERR, and found a few hits, but none that I could understand or use in this context.

Best Answer

I think you want to put the output redirection before the pipe, so that it applies to tcpdump's output, not grep's.

tcpdump -A -r capture.pcap 2>&1 | grep interesting-string > /dev/null
Related Question