How to use the command bluetoothctl (with examples)
- Linux
- December 25, 2023
Bluetoothctl is a command-line tool for managing Bluetooth devices. It allows users to interact with the Bluetooth device manager and perform various operations such as pairing, connecting, and removing devices. This article will provide examples of different use cases for the bluetoothctl
command.
Use case 1: Entering the bluetoothctl shell
Code:
bluetoothctl
Motivation: Entering the bluetoothctl shell allows users to access the interactive command-line interface for managing Bluetooth devices. This is the starting point for using any of the other commands provided by bluetoothctl.
Explanation:
Running the command bluetoothctl
starts the bluetoothctl shell, launching an interactive prompt where you can input commands to manage Bluetooth devices.
Example output:
[bluetooth]#
Use case 2: Listing all known devices
Code:
bluetoothctl devices
Motivation: Listing all known devices provides users with an overview of the Bluetooth devices that have been discovered and stored by the Bluetooth device manager. This can be helpful when trying to identify or troubleshoot devices.
Explanation:
By running the bluetoothctl devices
command, a list of all known devices will be displayed. Each device is listed with its MAC address and name.
Example output:
Device 1: XX:XX:XX:XX:XX:XX Device Name 1
Device 2: YY:YY:YY:YY:YY:YY Device Name 2
Device 3: ZZ:ZZ:ZZ:ZZ:ZZ:ZZ Device Name 3
Use case 3: Powering the Bluetooth controller on or off
Code:
bluetoothctl power on|off
Motivation: Powering the Bluetooth controller on or off allows users to enable or disable the Bluetooth functionality on their device. Disabling Bluetooth can be useful to conserve energy or when not using Bluetooth devices for an extended period.
Explanation:
The argument on
is used to power on the Bluetooth controller, enabling it to scan and connect to other devices. Conversely, the argument off
is used to power off the Bluetooth controller, disabling its functionality.
Example output:
Changing power off succeeded
Use case 4: Pairing with a device
Code:
bluetoothctl pair mac_address
Motivation: Pairing with a device establishes a secure connection between your device and the Bluetooth device you want to connect to. This is necessary before being able to use most Bluetooth features, such as transferring files or streaming audio.
Explanation:
To pair with a device, you need to provide the MAC address of the device you wish to pair with. Replace mac_address
in the command with the actual MAC address of the device.
Example output:
Attempting to pair with XX:XX:XX:XX:XX:XX
Pairing successful
Use case 5: Removing a device
Code:
bluetoothctl remove mac_address
Motivation: Removing a device from the list of known devices can be helpful when you no longer want to connect or interact with a specific Bluetooth device. This can help in decluttering the list of devices or if you are no longer using a device.
Explanation:
To remove a device, you need to provide the MAC address of the device you wish to remove. Replace mac_address
in the command with the actual MAC address of the device.
Example output:
Device XX:XX:XX:XX:XX:XX has been removed
Use case 6: Connecting to a paired device
Code:
bluetoothctl connect mac_address
Motivation: Connecting to a paired device allows users to establish a connection with a Bluetooth device that has already been paired. Once connected, you can use the Bluetooth device for various operations such as sending and receiving data.
Explanation:
To connect to a paired device, you need to provide the MAC address of the device you wish to connect to. Replace mac_address
in the command with the actual MAC address of the device.
Example output:
Attempting to connect to XX:XX:XX:XX:XX:XX
Connection successful
Use case 7: Disconnecting from a paired device
Code:
bluetoothctl disconnect mac_address
Motivation: Disconnecting from a paired device is useful when you want to terminate the connection between your device and a Bluetooth device. This can be helpful in situations where you no longer need the Bluetooth connection.
Explanation:
To disconnect from a paired device, you need to provide the MAC address of the device you wish to disconnect from. Replace mac_address
in the command with the actual MAC address of the device.
Example output:
Disconnected from XX:XX:XX:XX:XX:XX
Use case 8: Displaying help
Code:
bluetoothctl help
Motivation: Displaying help provides users with information on how to use the different commands available in bluetoothctl. This can be helpful if you need a quick reference or if you are unsure about the usage of a specific command.
Explanation:
Running the bluetoothctl help
command displays a list of available commands and a brief description of each command.
Example output:
Available commands:
list
show [ctrl]
select <ctrl>
devices
paired-devices
system-alias
connect <address>
disconnect
remove <address>
power <on/off>
mode <mode>
agent <on/off/capability/timeout>
default-agent
scan <on/off>
pairable <on/off>
pair <address>
discoverable <on/off>
info <address>
menu <command>
quit
Conclusion:
The bluetoothctl
command is a powerful tool for managing Bluetooth devices on Linux systems. Whether you need to pair, connect, or remove devices, bluetoothctl provides the necessary commands for these operations. By following the examples and explanations provided in this article, users can effectively utilize bluetoothctl to control and manage their Bluetooth devices.