What is the function of the netstat command in Linux, and what steps are involved in viewing network connections and listening ports within the Linux operating system?