Q1: How to scan for all nearby wireless access point (AP) on Linux, in particular, Ubuntu or Debian?
A: Here is one solution
sudo iwlist wlan0 scanning | egrep 'Cell |Encryption|Quality|Last beacon|ESSID' should help.
It’s the combination of
sudo (run as root, do privileged operations),
iwlist wlan0 scanning (produce some output on STDOUT), the pipe symbol “|” (connecting STDOUT of the command(s) to the left to the STDIN of the process on the right), and an
egrep command with a “single quoted” (to prevent the shell from interpreting the “|” characters) Regular Expression to filter STDIN. See
man egrep, and
man re_format for details.
ALWAYS do man whatever (as above) BEFORE you execute a command string from someone else. Self-education is much safer than blind trust.