14
votes

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.

6
Could you share with me how exactly do you use the hcitool on OS X to scan for BTRuskes

6 Answers

8
votes

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

8
votes

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.

6
votes

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>
3
votes

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

3
votes

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
1
votes

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 :)