Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to set the audio volume using the terminal?, instead of clicking the speaker icon in the topbar, the reason I want need to do this is because my keyboard does not have a volume increase/decrease buttons and I find it annoying to reach for the mouse.

share|improve this question
up vote 49 down vote accepted

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%
share|improve this answer

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.

share|improve this answer

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.

share|improve this answer

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"
share|improve this answer
    
Worth noting that you can also use the Mac volume buttons to change volume by fractional increments. – Wildcard Feb 17 at 8:04

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.
share|improve this answer
    
Note from arch linux wiki: 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 8:01
    
@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
    
@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
1  
@JamieCockburn i'm running ubuntu 16.04 xfce bash, and it works perfectly witout "--", just a note. – Reishin Feb 15 at 15:47

I know this is an old one. Since Alsa and pulseaudio are so connected, this awnser from askubuntu: http://askubuntu.com/a/444183 helped me to 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 works too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.