I switch between a USB webcam/mic and my internal mic and the other solutions typically work on the "default" device which is often not the device I'm actively using so I wrote this to mute all microphones
pacmd is the command line interface to PulseAudio (the sound subsystem used in recent releases). I don't know what the exact command is you'd need but I think you'd want to play with the set-sink-input-mute function.
pacmd is interactive when run without instructions so you have a good opportunity to play around with it and convert that into a one-line function for toggling mute.
I like to create my own terminal stupid shortcuts. So to configrure m = mute; mm = unmute
I added this to ./.bashrc
alias m="amixer set Capture nocap"
alias mm="amixer set Capture cap"
interesting enough, yesterday I've re-enable autostart of "Screen Locker (Launch screen locker program) in the menu> sessions and startup > Application Autostart and now my hardware mute button start working (after restart) I have no idea why (XFCE Xubuntu 18.08)
I'm still keeping those terminal shortcuts but just wanted to point out
Select some way to identify the correct card. If you trust that your configuration does not change, you can use card number and simply run (e.g. if you want to control the card 1):
pactl set-source-mute 1 toggle
However, if you instead want to prepare for a case where e.g. your USB connected source is not always connected and you only want to mute that, you can use some way to detect it from the above output. Let's say you want to control the LifeCam HD-5000 only. Then you could do it like this:
This queries all audio sources from PulseAudio, extracts card rows that have LifeCam_HD-5000 as part of their name, uses awk to extract the second part of the row to get the card number and passes it to pactl to toggle correct source muting using xargs to put the number in correct position in the command. The -rn1 flag tells xargs to do nothing if the card number couldn't be found.
If you need to know the mute status for some scripting, you can do