parecord
The parecord (“Pulse Audio record”) command is a tool that lets you record anything passing through your system's sound system. You can use it to record streaming music, Internet radio interviews, sound effects, and anything else your computer is playing at any given moment. If you can hear it through your computer speakers, you can record it.
Install
As long as you have Pulse Audio installed, you already have the parecord command.
Configuration
The parecord command counts on you knowing your own computer's audio configuration. This can seem overwhelming if you're not used to how Linux systems categorise audio, and even moreso if you have a computer with a complex audio setup.
From the perspective of Pulse Audio itself, there are two kinds of audio: sinks and sources. Applications using Pulse Audio send audio to sinks and they receive audio from sources.
If you want to record everything happening on a system, then you want to record the monitor device: a special stream that mixes everything happening on your system together and plays it through your computer speaker.
Find the device name:
$ pacmd list-sources | grep name: name: <alsa_output.pci-0000_00_1b.0.analog-stereo.monitor> name: <alsa_input.pci-0000_00_1b.0.analog-stereo>
The first device in this example, with the suffix monitor, is the stream that you hear over your computer speakers, meaning it's everything being sent to Pulse Audio.