Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically removing all bluetooth devices on the Linux command line

I am able to scan for all available bluetooth devices with hcitool or with my C program.

I can pair the device using it's address with a simple-agent python script.

I would like to know if I can also remove the paired device using either hcitool, hciconfig or some kind of bluetooth command.

I know the information of detected devices for the hci0 controller is stored in /var/lib/bluetooth/XX:XX:XX:XX:XX:XX, where XX:XX:XX:XX:XX is the address of the hci controller.

This would be useful for testing pairing, connecting and disconnecting devices.

like image 507
user2570136 Avatar asked Jul 10 '13 20:07

user2570136


1 Answers

For those using Ubuntu 20.04, here is the same command using the bluetoothctl command

#!/bin/bash 
for device in $(bluetoothctl devices  | grep -o "[[:xdigit:]:]\{8,17\}"); do
    echo "removing bluetooth device: $device | $(bluetoothctl remove $device)"
done
like image 155
user15764068 Avatar answered Sep 29 '22 00:09

user15764068