TCPDump Man Page – How to Read and Understand Options

manoptions

I am trying to use the tcpdump command in a project and I have some difficulties understanding the help page.

SYNOPSIS
   tcpdump [ -AbdDefhgHIJKlLnNoOpPqRStuUvxX ] [ -B buffer_size ] [ -c
   count ]
           [ -C file_size ] [ -G rotate_seconds ] [ -F file ]
           [ -i interface ] [ -j tstamp_type ] [ -k (metadata_arg) ]
           [ -m module ] [ -M secret ]
           [ -r file ] [ -s snaplen ] [ -T type ] [ -w file ]
           [ -W filecount ]
           [ -E spi@ipaddr algo:secret,...  ]
           [ -y datalinktype ] [ -z postrotate-command ] [ -Z user ]
           [ -Q packet-metadata-filter ]
           [ expression ]

First, what is this "[ -AbdDefhgHIJKlLnNoOpPqRStuUvxX ]" at the top ? What is the meaning of that ?
I also see a lot of people on the internet doing crazy things with this command, for example tcpdmp -nnvvXSs 1514 … what is that -nnvvXSs, and how can we know this can be used ?

I see codes examples that according to me does not correspond to the man page, I just don't get how to read, how to understand this help file.

Anybody tell me how to read this and understand it ?

Best Answer

By convention, the brackets indicate something that is optional. So you can run tcpdump, or tcpdump -c 3 -i eth0, or tcpdump -c 3 -r /path/to/file, etc. Also, unless explicitly indicated, options can be used in any order, so you can run tcp -i eth0 -c 3, etc.

Most commands allow options to be clustered when they use a single letter. For example, tcpdump -AX is equivalent to tcpdump -A -X. The manual groups all options that don't take arguments to make the presentation shorter: [ -Abd ] would be a shortcut for [ -A ] [ -b ] [ -d ], etc.

The synopsis is just a summary. Read the “description” or “options” section to see what each option does and what the word after each option can be replaced with.

For example, tcpdmp -nnvvXSs 1514 is a shorter equivalent of tcpdump -n -n -v -v -X -s -s 1514, and means:

  • -n: don't do name resolution. Repeating this option has no additional effect.
  • -v: causes tcpdump to print out more stuff. Repeating this option causes it to print even more stuff.
  • -X adds a dump of the content of each packet to the output.
  • -S causes absolute TCP sequence numbers to be printed.
  • -s 1514 causes only the first 1514 bytes of each packet to be captured.
Related Question