How to use command line to change volume?

You can use amixer. It's in the alsa-utils package on Ubuntu and Debian.

Run amixer without parameters to get an overview about your controls for the default device.

You can also use alsamixer without parameters (from the same package) to get a more visual overview. Use F6 to see and switch between devices. Commonly you might have PulseAudio and a hardware soundcard to select from.

Then use amixer with the set command to set the volume. For example, to set the master channel to 50%:

amixer set Master 50%

Master is the control name and should match one that you see when running without paramters.

Note the % sign, without it it will treat the value as 0 - 65536 level.

If PulseAudio is not your default device, you might can use the -D switch:

amixer -D pulse set Master 50%

Other useful commands pointed out in the comments:

To increase/decrease the volume use +/- after the number, use

amixer set Master 10%+
amixer set Master 10%-

To mute, unmute or toggle between muted/unmuted state, use

amixer set Master mute
amixer set Master unmute
amixer set Master toggle

Also note that there might be two different percentage scales, the default raw and for some devices a more natural scale based on decibel, which is also used by alsamixer. Use -M to use the latter.

Finally, if you're interested in PulseAudio only, you might want to check out pactl (see one of the other answers).


To mute:

amixer -D pulse sset Master mute

To unmute:

amixer -D pulse sset Master unmute

To turn volume up 5%:

amixer -D pulse sset Master 5%+

To turn volume down 5%:

amixer -D pulse sset Master 5%-

pactl/pacmd (unlike amixer) allows increasing volume over 100% :-).

pactl set-sink-mute 0 toggle  # toggle mute, also you have true/false
pactl set-sink-volume 0 0     # mute (force)
pactl set-sink-volume 0 100%  # max
pactl set-sink-volume 0 +5%   # +5% (up)
pactl set-sink-volume 0 -5%   # -5% (down)

Manual settings over 100% is possible in pavucontrol (unlike alsamixer).

Note: If you want to share the same commands on different hosts with different sinks, you can use @DEFAULT_SINK@ as a sink instead of number 0:

pactl set-sink-volume @DEFAULT_SINK@ +5%

You set your default sink with pactl set-default-sink my-sink-name (list names with pactl list short sinks).

Source: askubuntu.com, wiki.archlinux.org.