Unix & Linux: How do I make my pc speaker beep? (10 Solutions!!)
Channel: Roel Van de Paar
Date: 2020-08-07

Unix & Linux: How do I make my pc speaker beep?


The Question: Using bash, how can I make the pc speaker beep?
Something like echo 'beepsound' ＞ /dev/pcspkr would be nice.

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 13 people ==
Some distros have command-line utilities to achieve this. Maybe you could tell
us what distro you are on, or search (e.g. emerge -s beep in gentoo).
Going beyond "available" utils, you could also make a Perl script that emits
the beep, all you need to do is include:
＜SomeCodeBefore＞
print "007";
＜SomeCodeAfter＞
If you do end up getting 'beep', try out the following:
#! /bin/sh

beep -f 500 -l 700
beep -f 480 -l 400
beep -f 470 -l 250
beep -f 530 -l 300 -D 100
beep -f 500 -l 300 -D 100
beep -f 500 -l 300
beep -f 400 -l 600
beep -f 300 -l 500
beep -f 350 -l 700
beep -f 250 -l 600

== This solution helped 2 people ==
Try
echo -n Ctrl+V Ctrl+G
The downside is that this will work only when the output device is a terminal,
so it may not work inside a cron job, for instance. (But if you are root you
might be able redirect to /dev/console for immediate beeping.)

== This solution helped 77 people ==
Simply echoing a or 07 works for me.
$ echo -e "a"
This will probably require the pcspkr kernel module to be loaded. I've only
tested this on RHEL, so YMMV.
**** UPDATE ****
As Warren pointed out in the comments, this may not work when logged in
remotely via SSH. A quick workaround would be to redirect the output to any of
the TTY devices (ideally one that is unused). E.g.:
$ echo -en "a" ＞ /dev/tty5

== This solution helped 134 people ==
I usually use the little utility beep installed on many systems. This command
will try different approaches to create a system sound.
There are 3 ways of creating a sound from the beep manpage:
 1. The traditional method of producing a beep in a shell script is to write
 an ASCII BEL (007) character to standard output, by means of a shell
 command such as
 echo -ne '007'
 This only works if the calling shell's standard output is currently
 directed to a terminal device of some sort; if not, the beep will produce
 no sound and might even cause unwanted corruption in whatever file the
 output is directed to.
 2. There are other ways to cause a beeping noise. A slightly more reliable
 method is to open /dev/tty and send your BEL character there. This is
 robust against I/O redirection, but still fails in the case where the
 shell script wishing to generate a beep does not have a controlling
 terminal, for example because it is run from an X window manager.
 3. A third approach is to connect to your X display and send it a bell
 command. This does not depend on a Unix terminal device, but does (of
 course) require an X display.
beep will simply try these 3 methods.

In a terminal, press Ctrl+G and then Enter

== This solution helped 32 people ==
tput bel
because terminfo defines bel as
 Variable Cap- TCap
Description
String name Code

bell bel bl
audible signal
(bell) (P)
With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user wormintrude (https://unix.stackexchange.com/users/1074), user Winston Smith (https://unix.stackexchange.com/users/7810), user user123456 (https://unix.stackexchange.com/users/189711), user Stefan (https://unix.stackexchange.com/users/1327), user slm (https://unix.stackexchange.com/users/7453), user Shawn Chin (https://unix.stackexchange.com/users/292), user Ryne Everett (https://unix.stackexchange.com/users/43610), user MvG (https://unix.stackexchange.com/users/20807), user Michael Mrozek (https://unix.stackexchange.com/users/73), user Hitesh Chechani (https://unix.stackexchange.com/users/30565), user G-Man Says 'Reinstate Monica' (https://unix.stackexchange.com/users/80216), user Elliptical view (https://unix.stackexchange.com/users/181039), user echox (https://unix.stackexchange.com/users/1339), user codehead (https://unix.stackexchange.com/users/188), user Braiam (https://unix.stackexchange.com/users/41104), user Alexander (https://unix.stackexchange.com/users/3920), and the Stack Exchange Network (http://unix.stackexchange.com/questions/1974). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.