Generally, there are a few ways to get audio playback and recording devices on Linux. I'm focusing on command-line tools in this answer.
With PipeWire tools
If you are running PipeWire as your sound server, you can use pw-cli
to get the names of all your inputs and outputs (recording and playback devices):
pw-cli list-objects | grep node.name
Example output:
node.name = "Dummy-Driver"
node.name = "Freewheel-Driver"
node.name = "Midi-Bridge"
node.name = "v4l2_input.pci-0000_00_1a.0-usb-0_1.6_1.0"
node.name = "alsa_output.pci-0000_00_1b.0.analog-stereo"
node.name = "alsa_input.pci-0000_00_1b.0.analog-stereo"
node.name = "alsa_input.usb-UC_Mic_USB_Audio_Device-00.mono-fallback"
These node names can be used to record audio from the command line.
See also pw-link
which can list input and output PipeWire ports.
With PulseAudio tools
Alternatively, you can use command-line tools that come with PulseAudio (another sound server) to do the same:
pactl list | grep node.name
This produces similar output to pw-cli list-objects
on my machine:
node.name = "alsa_output.pci-0000_00_1b.0.analog-stereo"
node.name = "alsa_output.pci-0000_00_1b.0.analog-stereo"
node.name = "alsa_input.pci-0000_00_1b.0.analog-stereo"
node.name = "alsa_input.usb-UC_Mic_USB_Audio_Device-00.mono-fallback"
I found it useful to only display audio sinks, like loudspeakers and headphones:
pactl list short sinks
Example output:
43 alsa_output.pci-0000_00_1b.0.analog-stereo PipeWire s32le 2ch 48000Hz IDLE
1076 alsa_output.usb-Logitech_Logitech_Wireless_Headset_4473D63ED97A-00.analog-stereo PipeWire s16le 2ch 48000Hz IDLE
Mind that even if you use PipeWire as your audio server, pactl
will probably still work since PipeWire aims to be a drop-in replacement for PulseAudio.
With ALSA tools
As shown in user4124's answer, you can list playback devices (e.g., headphones, loudspeakers) using ALSA's command-line tools:
aplay --list-devices
Sample output for playback devices on my machine:
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CX20590 Analog [CX20590 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
Subdevices: 1/1
Subdevice #0: subdevice #0
For recording devices, use
arecord --list-devices
Sample output for recording devices on my machine:
**** List of CAPTURE Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: CX20590 Analog [CX20590 Analog]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: Device [USB Audio Device], device 0: USB Audio [USB Audio]
Subdevices: 1/1
Subdevice #0: subdevice #0
See also the --list-pcms
option from the man page to list all PCM devices.