tee
save and show at oncetee sits in a pipe and sends what passes through to two places: a file, and onward. Named after a T-shaped pipe joint, it is also the standard way to write to a root-owned file from a pipe.
A redirect sends output to a file instead of the screen; tee sends it to both.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
tee passes everything through to the screen, so the command can be watched while it runs.
The same three lines are in ping.log.
tee runs under sudo, so it may open /etc/hosts. -a appends instead of replacing. The line is echoed back because tee also prints.
Switches
A switch changes how the command behaves. These are the ones used day to day; man tee lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
-a- Append to the file instead of overwriting it.
-i- Ignore interrupt signals, so Ctrl+C does not stop tee before the command.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
make 2>&1 | tee build.logSaves both normal output and errors while showing them.
command | tee -a history.logAppends to a log instead of overwriting it.
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forwardWrites a kernel setting that needs root.
command | sudo tee file > /dev/nullWrites the file without echoing the content to the screen.
In cybersecurity
tee is how a record is kept of what a command actually printed.
During an investigation or an authorised test, piping commands through tee keeps a dated record of exactly what was seen.
sudo tee /etc/hosts without -a replaces the whole file with one line. Check for the -a every time.
A log made with tee holds whatever the command printed, tokens and passwords included. Give it tight permissions.