21

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.

Levent Divilioglu
  • 11,198
  • 5
  • 59
  • 106
user2570136
  • 221
  • 1
  • 2
  • 3

6 Answers6

16

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
user15764068
  • 169
  • 1
  • 2
8

bluez-test-device remove XX:XX:XX:XX:XX:XX

ashish
  • 1,384
  • 1
  • 12
  • 21
8

If you install the bluez-tools package, run this to unpair a bluetooth device :

bt-device -r xx:xx:xx:xx:xx:xx

where xx:xx:xx:xx:xx:xx is the address of the paired device.

BЈовић
  • 62,405
  • 41
  • 173
  • 273
6

As it is mentioned above on ashish's answer, you can us bluez-test-device to remove the device which that you already know its mac address. So the problem is to parse the mac address of the added devices.

With python or c or whatever you use,

1) list the devices with;

bluez-test-device list

and parse the output and get all the MAC addresses of the devices, add them to a list.

2) disconnect and remove the devices;

bluez-test-device disconnect <MAC ADDRESS>
bluez-test-device remove <MAC ADDRESS>
Levent Divilioglu
  • 11,198
  • 5
  • 59
  • 106
5

Command using bluetoothctl binary: for device in $(bluetoothctl devices | grep -vEi '(o que mais vc quer deixar aqui|samsung|jbl|wireless)' | awk '{print $2}'); do bluetoothctl remove $device; done

dejanualex
  • 3,872
  • 6
  • 22
  • 37
3

All these answers don't answer the headline "removing all Bluetooth devices"

I wrote this little bash script to remove all the Bluetooth devices that are listed in the bt-device -l

#!/bin/bash 
for device in $(bt-device -l | grep -o "[[:xdigit:]:]\{11,17\}"); do
    echo "removing bluetooth device: $device | $(bt-device -r $device)"
done

How to run?

  1. Make a new file like <fileName>.sh and paste the code above.
  2. Run chmod +x <fileName> to make the script executable
  3. Run ./<fileName>.sh
  4. Celebrate! All Bluetooth devices are removed now :)
Jesse de gans
  • 1,432
  • 1
  • 14
  • 27