113

How do you mute the sound system from the command line?

Braiam
  • 66,947
  • 30
  • 177
  • 264
myusuf3
  • 33,569
  • 41
  • 88
  • 103

6 Answers6

91

Assuming you're using ALSA driver, run:

amixer set Master mute   
amixer set Master unmute

Or, you can just use:

amixer set Master toggle

to toggle mute on and off.

Eric Carvalho
  • 53,609
  • 102
  • 137
  • 162
goric
  • 3,756
  • 3
  • 27
  • 24
  • 8
    for me / my system (precise), this only goes one way: off / mute. Neither toggle nor unmute bring the music back on. Any ideas as to why?? – nutty about natty May 08 '12 at 13:12
  • 2
    see http://askubuntu.com/questions/77522/command-to-unmute-and-maximize-volume – nutty about natty May 08 '12 at 13:17
  • 3
    This solution is for pure Alsa. For Alsa with pulseaudio, use the command from [Tim's answer](http://askubuntu.com/a/444183). Or don't touch the command and instead configure Alsa as in [this answer](http://askubuntu.com/a/517453). Else, @nutty about natty's problem of not being able to unmute results. – tanius Feb 17 '16 at 01:32
  • on Ubuntu Server 14.04 "Master" was not available as a simple control. I used "Speaker" in its place. I found the substitution by running `sudo amixer` and finding the line in the output that matched `Simple mixer control 'Speaker',0` – brycemcd Oct 02 '16 at 20:11
63

This worked for me when others didn't:

amixer -q -D pulse sset Master toggle

This is from the link in nutty about natty's comment to the first answer:

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Tim
  • 32,274
  • 27
  • 118
  • 177
  • 1
    I also just checked, it works on 14.04 too. – Tim May 30 '14 at 08:59
  • 1
    did it :) - kubuntu here (Ubuntu 14.04.2 LTS). thx. – hakre Jul 02 '15 at 18:28
  • 2
    This `-D pulse` option is needed when Alsa is used with pulseaudio (and since the question is tagged pulseaudio, this should be the accepted answer). For more details about this solution, see [here](http://askubuntu.com/questions/544754) and [here](http://askubuntu.com/questions/118675) on askubuntu. – tanius Feb 17 '16 at 01:23
  • Note: The accepted answer by @goric doesn't work when headphones or earphones are plugged in, use this. –  May 27 '16 at 12:34
  • Or, less ambiguously than "toggle", you can use `amixer -q -D pulse sset Master mute` and `amixer -q -D pulse sset Master unmute`. Works great on Ubuntu 16.04 – CPBL Jun 30 '16 at 13:00
  • @CPBL sure, that didn't work for me when I answered this – Tim Jun 30 '16 at 16:34
  • this also worked for me to mute the bluetooth speaker, which was not affected by the default laptop button –  Jul 23 '18 at 09:42
47

I'm using pactl in my scripts. From man page:

set-sink-mute SINK 1|0|toggle: Set the mute status of the specified sink (identified by its symbolic name or numerical index)

To mute:

pactl set-sink-mute @DEFAULT_SINK@ true

To unmute:

pactl set-sink-mute @DEFAULT_SINK@ false

To toggle:

pactl set-sink-mute @DEFAULT_SINK@ toggle

Use 0 instead of @DEFAULT_SINK@ to set the sink with numerical index 0. true=="1", false=="0".

Tested on Ubuntu 12.10.
In my setup sometimes amixer unmute fails for some reason.

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
Niko Riitala
  • 571
  • 4
  • 3
17

On the terminal type this to mute

amixer set Master mute

type

amixer set Master unmute

Tested on my Ubuntu 10.10.

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
theTuxRacer
  • 15,945
  • 22
  • 71
  • 91
10

If you are using alsa follow goric answer.

PulseAudio is better, but not so simple: pactl set-sink-mute 0 1 Do the work for the first device, but not if you are using headphones of another sink output.

The better way is to check with pactl info and get the Default Sink to use.

DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)

Then to mute:

pactl set-sink-mute "$DEFAULT_SINK" "1"

Or unmute:

pactl set-sink-mute "$DEFAULT_SINK" "0"

I wrote a script to manage pulseaudio in my note. If you want to use, save it as volume, provide execute permissions chmod +x volume and add it to your path ln -sv $PWD/volume /usr/local/bin/. Here my script:

#!/bin/bash
# script name: volume
# Author: glaudistong at gmail.com
# depends on: yad, coreutils, pulseaudio

ps -ef | grep "yad" | grep -E "Volume [^+\-]" | tr -s " " | cut -d " " -f2 | xargs -i kill "{}" 2>/dev/null
DEFAULT_SINK=$(pactl info | grep "Default Sink" | cut -d " " -f3)
DEFAULT_SOURCE=$(pactl info | grep "Default Source" | cut -d " " -f3)
case "$1" in 
    init)
    {
        ps -fe | grep yad | grep -q volume ||
        {
         yad --notification --command "volume up" --text "+ Volume +" --image ~/Pictures/volume-up-dark.png &
         yad --notification --command "volume down" --text "- Volume -" --image ~/Pictures/volume-down-dark.png &
        }
    };;
    up)
    {
        pactl set-sink-volume "$DEFAULT_SINK" +5%
        P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
        iconl="$(echo -ne "\U1F50A")"
        iconr="$(echo -ne "\U1F56A")"
        timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
    };;
    down)
    {
        pactl set-sink-volume "$DEFAULT_SINK" -5%
        P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
        iconl="$(echo -ne "\U1F509")"
        iconr="$(echo -ne "\U1F569")"
        timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$iconl Volume $P% $iconr" --no-focus --center --skip-taskbar --on-top &
    };;
    mute)
    {
        ismute=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
        if [ "$ismute" == no ]; then
            s=1
            P=0
            icon="$(echo -ne "\U1F507")"
        else
            P=$(pactl list | grep -E "Name: $DEFAULT_SINK$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
            icon=""
            s=0
        fi
        pactl set-sink-mute "$DEFAULT_SINK" "$s"
        echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::mute/brightness
        timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume $P%" --no-focus --center --skip-taskbar --on-top &
    };;
    mic-up)
    {
        pactl set-source-volume "$DEFAULT_SOURCE" +5%
        P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
        icon="$(echo -en "\U1F3A4")"
        timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
    };;
    mic-down)
    {
        pactl set-source-volume "$DEFAULT_SOURCE" -5%
        icon="$(echo -en "\U1F3A4")"
        P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
        timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
    };;
    mic-mute)
    {
        ismute=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Mute" | grep "Name:" -A1 | tail -1 |cut -d: -f2| tr -d " ")
        if [ "$ismute" == no ]; then
            s=1
            P=0
            icon="$(echo -en "\U1F507\U1F3A4")"
        else
            P=$(pactl list | grep -E "Name: $DEFAULT_SOURCE$|Volume" | grep "Name:" -A1 | tail -1 | cut -d% -f1 | cut -d/ -f2 | tr -d " ")
            s=0
            icon="$(echo -en "\U1F3A4")"
        fi
        pactl set-source-mute "$DEFAULT_SOURCE" "$s"
        echo $s > /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness
        timeout .6 yad --progress --percentage "$P" --timeout 1 --no-buttons --undecorated --text="$icon Volume Mic $P%" --no-focus --center --skip-taskbar --on-top &
    };;
    *)
        echo invalid option;;
esac;
Kulfy
  • 17,416
  • 26
  • 64
  • 103
ton
  • 201
  • 2
  • 4
  • 1
    As a minor improvement, you can reference the default sink/source with a value of `@DEFAULT_SINK@` and `@DEFAULT_SOURCE@` respectively, instead of grepping the output of a query. – ForeverZer0 Aug 18 '23 at 05:46
2

if your are using pulseaudio as the sound server then do this

pactl -- set-sink-mute @DEFAULT_SINK@ toggle # Also true/false to mute/unmute

to mute and unmute

if using alsa then use this

amixer sset 'Master' toggle

to mute and unmute

Pablo Bianchi
  • 14,308
  • 4
  • 74
  • 117
bhanu pratap
  • 161
  • 3