112

Is it possible to set the audio volume using the terminal instead of clicking the speaker icon in the top bar?

The reason I want to do this is that my keyboard does not have volume increase/decrease buttons and I find it annoying to reach for the mouse.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
Tristian
  • 1,499
  • 2
  • 13
  • 13
  • 2
    Read Master Volume level in number percent 0%-100%: `amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }'` Increase Master volume level by 10%: `amixer -q sset Master 10%+` – Eric Leschinski Jan 21 '19 at 18:04

8 Answers8

121

For interactive usage you can use alsamixer. For scripting (e.g. binding to key combinations) take a look at amixer.

alsamixer is included by default in most systems.


To set the master volume use:

# Gets a list of simple mixer controls
$ amixer scontrols 

Then set it to the desired volume, as an example

$ amixer sset 'Master' 50%
Tristian
  • 1,499
  • 2
  • 13
  • 13
Renan
  • 16,976
  • 8
  • 69
  • 88
  • 3
    What is the different between "sset" and just "set". (I tried both, and both work) – Venryx Dec 06 '17 at 21:39
  • @Venryx `man amixer` suggests that the they are equivalent and that the "s" in "sset" stands for "simple". There's also a "cset" that sets card control contents. – Matthias Braun Oct 07 '18 at 13:25
  • 4
    Added the following to my `.bashrc` to make this command easier: `volume() { amixer sset 'Master' $1%; }` – Philip Kirkbride Jan 24 '20 at 16:21
56

Found in Openbox's configuration file rc.xml:

# increase by 3%
amixer -q sset Master 3%+

# decrease by 3%
amixer -q sset Master 3%-

# mute/unmute
amixer -q sset Master toggle

amixer manual page can give more details.

enzotib
  • 50,671
  • 14
  • 120
  • 105
34

If your system is using pulseaudio you could use pactl:

pactl set-sink-volume 0 +15%

or

pactl set-sink-volume 0 -5dB

though you could also specify an integer or a linear factor:

set-sink-volume SINK VOLUME [VOLUME ...]
          Set the volume of the specified sink (identified by its symbolic name or numerical index). VOLUME can be speci‐
          fied as an integer (e.g. 2000, 16384), a linear factor (e.g. 0.4, 1.100), a percentage (e.g. 10%, 100%) or a
          decibel value (e.g. 0dB, 20dB). If the volume specification start with a + or - the volume  adjustment  will  be
          relative to the current sink volume. A single volume value affects all channels; if multiple volume values are
          given their number has to match the sink's number of channels.
don_crissti
  • 79,330
  • 30
  • 216
  • 245
  • 2
    Note from [arch linux wiki](https://wiki.archlinux.org/index.php/PulseAudio/Troubleshooting): `pactl` commands that take negative percentage arguments will fail with an 'invalid option' error. Use the standard shell `--` pseudo argument to disable argument parsing before the negative argument. e.g. `pactl set-sink-volume 1 -- -5%` – Jamie Cockburn Aug 25 '15 at 08:01
  • 2
    @JamieCockburn - I'm not sure when was that written but _I use archlinux_ and there is absolutely no need for the additional `--` with negative values (percentage, db, integers... they all work fine). In fact, **it's quite the opposite**: if I use `--` as per the wiki e.g. `pactl set-sink-volume 1 -- -3%` I get `Invalid volume specification`. – don_crissti Aug 25 '15 at 10:02
  • Must be dependent on shell then? I'm on ubuntu 14.04, with Xfce, and running the command from bash (4.3.11). If I omit the `--`, I get an invalid option. – Jamie Cockburn Aug 25 '15 at 10:58
  • 2
    @JamieCockburn - I don 't think the shell is relevant (for the record, it works fine for me with both `bash` and `zsh`). Probably earlier versions of `pactl` had this problem and upstream most likely fixed it (I'm using v. 6.0). – don_crissti Aug 25 '15 at 11:08
  • Right, well the standard `pactl` bundled with this distro seems to be 4.0. Hopefully my comment this will help others facing this issue! – Jamie Cockburn Aug 25 '15 at 11:44
  • 1
    @JamieCockburn i'm running ubuntu 16.04 xfce bash, and it works perfectly witout "--", just a note. – Reishin Feb 15 '16 at 15:47
  • In my case I wanted to control a different sink so I used `pactl set-sink-volume 1 -5dB`. – Andrew Nov 07 '16 at 20:25
15

I know this is an old one. Since Alsa and pulseaudio are so connected, this answer from askubuntu helped me manage the volume from both my main sound and the HDMI:

increase volume

amixer -q -D pulse sset Master 10%+

decrease volume

amixer -q -D pulse sset Master 10%-

toggle mute

amixer -q -D pulse sset Master toggle

Other amixer sset commands work too.

Matthias Braun
  • 7,797
  • 7
  • 45
  • 54
Mathter
  • 251
  • 2
  • 4
9

These are "more natural for human ear".

To get the master in the alsamixer units, use:

amixer -M get Master

To raise the volume by 5% in the alsamixer units, for example:

amixer -M set Master 5%+

https://bbs.archlinux.org/viewtopic.php?id=135348

sam
  • 22,265
  • 4
  • 22
  • 30
Robson
  • 91
  • 1
  • 1
7

In OS X use the following:

# highest
osascript -e "set Volume 7"
# lowest
osascript -e "set Volume 1"
# middle
osascript -e "set Volume 3.5"  

You can even set the volume to other fractional levels:

# 25%
osascript -e "set Volume 1.75"
1''
  • 347
  • 1
  • 4
  • 7
  • Worth noting that you can also [use the Mac volume buttons to change volume by fractional increments](http://apple.stackexchange.com/a/568/151730). – Wildcard Feb 17 '16 at 08:04
  • @Wildcard the Mac volume buttons are only in increments of 0.25 – 1'' Sep 07 '16 at 02:35
6

you can also try pamixer, a recent project that does exactly what you want. It is in the ArchLinux AUR repository with the same name.

fradeve
  • 243
  • 2
  • 4
0

So, answer the question first: To increase the Master volume level by 10%, consider this snippet:

amixer -q sset Master 10%+

You can also set it to a specific value:

amixer -q sset Master 78%

This can also be found in other answers, but I try to extend to the comment by Eric Leschinski, which basically is a TL:DR;-ish answer.

To read the Master Volume level (human readable), you can use:

amixer sget Master  

To get the number in percent (from 0% to 100%), you can pipe it into grep and awk:

amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }'

On my notebook, I only have a mono-speaker, so the right code for me was:

amixer sget Master | grep 'Mono:' | awk -F'[][]' '{ print $2 }'