LinuxCommandLibrary

beep

Emit a short audible tone

TLDR

Play a beep

$ beep
copy

Play a beep that repeats
$ beep -r [repetitions]
copy

Play a beep at a specified frequency (Hz) and duration (milliseconds)
$ beep -f [frequency] -l [duration]
copy

Play each new frequency and duration as a distinct beep
$ beep -f [frequency] -l [duration] [[-n|--new]] -f [frequency] -l [duration]
copy

Play the C major scale
$ beep -f [262] [[-n|--new]] -f [294] [[-n|--new]] -f [330] [[-n|--new]] -f [349] [[-n|--new]] -f [392] [[-n|--new]] -f [440] [[-n|--new]] -f [494] [[-n|--new]] -f [523]
copy

SYNOPSIS

beep [options]

PARAMETERS

-f
    Specifies the frequency of the tone in Hertz. Default is typically 440 Hz.

-l
    Specifies the duration of the tone in milliseconds. Default is typically 200 ms.

-r
    Specifies the number of times the tone is repeated. Default is 1.

-d
    Specifies the delay in milliseconds between repetitions. Default is 0.

-n
    Don't search for sound card. Useful if you want to *only* use the internal PC speaker.

-c
    Use the sound card. useful when the internal PC speaker is not active or the command is being run in a location where it is active by default.

-e
    Play the tone using the specified device. Useful with the sound card usage.

DESCRIPTION

The beep command is a simple utility that produces a short, audible tone on the system's speaker. It's primarily used to provide auditory feedback for various events or as a basic notification mechanism.

Typically, beep uses the PC speaker, which is distinct from the sound card. On modern systems where the PC speaker is disabled or unavailable, beep may attempt to use the system's sound card, however this depends on underlying libraries and support. The tone's frequency, duration, and number of repetitions can often be adjusted via command-line parameters or through a configuration file (typically `/etc/beeprc`). Its simplicity makes it useful in scripts for signaling completion, errors, or other events that require user attention.

CAVEATS

The functionality of the beep command heavily relies on the availability of the PC speaker and appropriate hardware and drivers. On many modern systems, the PC speaker is either disabled by default or not present at all, causing beep to fail silently or produce no sound.

Sound card behavior can also depend heavily on the kernel's audio drivers and configuration, potentially causing issues when trying to play sounds through it.

CONFIGURATION FILE

The command often looks for a configuration file, usually `/etc/beeprc` or `~/.beeprc`, to customize default behavior. Settings defined in these files may override command-line parameters.

RETURN CODES

Typically returns 0 on success and a non-zero value on failure (e.g., if it can't access the speaker or sound card).

ROOT PRIVILEGES

On some systems, using beep may require root privileges, particularly when interacting with the PC speaker or sound card directly. This is due to access restrictions on hardware devices.

HISTORY

The beep command has been around for a long time, likely originating in the early days of Unix and Linux, coinciding with the prevalence of the PC speaker. Its initial purpose was to provide a simple audible alert. Over time, variations and implementations have emerged, offering more customization options for tone frequency, duration, and repetition. While its significance has diminished with the advent of sophisticated audio subsystems, it remains a handy tool for basic notifications and auditory cues, especially in scripting environments.

SEE ALSO

Copied to clipboard