如何通过终端检查蓝牙状态

我正在寻找一种方法,通过终端检查我的笔记本电脑上的蓝牙是否已启用或禁用。有没有一个命令可以用来查找这些信息?

相关链接:https://askubuntu.com/questions/591803/how-to-check-bluetooth-version-on-my-laptop - Denilson Sá Maia
6个回答

除了检查服务,您还可以使用以下命令:
hcitool dev

这将返回所有已打开的设备。

我想我需要更好地表达我的问题。这个回答给了我所需要的东西。有了这个,我可以根据设备是否显示来判断它是开着还是关着。谢谢你的回复。 - ForgeSHIELD
2hcitool con 对我有效。 - Kira

使用hciconfig -a获取更多信息

hciconfig -a提供了更多的信息,包括蓝牙版本。

$ hciconfig -a
hci0:   Type: Primary  Bus: USB
    BD Address: 00:1A:7D:DC:70:13  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING PSCAN 
    RX bytes:1013 acl:0 sco:0 events:60 errors:0
    TX bytes:4890 acl:0 sco:0 commands:60 errors:0
    Features: 0xff 0xff 0x8f 0xfe 0xdb 0xff 0x5b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
    Link policy: RSWITCH HOLD SNIFF PARK 
    Link mode: SLAVE ACCEPT 
    Name: 'hostname'
    Class: 0x1c0104
    Service Classes: Rendering, Capturing, Object Transfer
    Device Class: Computer, Desktop workstation
    HCI Version: 4.0 (0x6)  Revision: 0x22bb
    LMP Version: 4.0 (0x6)  Subversion: 0x22bb
    Manufacturer: Cambridge Silicon Radio (10)

只需在键盘上按下Ctrl+Alt+T即可打开终端。打开后,您可以运行此命令来查看蓝牙的状态。
sudo service bluetooth status

输入密码后,你应该看到类似的提示:

蓝牙正在运行


6无论蓝牙是否开启,我都会从该命令收到相同的消息: 蓝牙已启动/运行,进程号1132 - ForgeSHIELD
蓝牙图标消失了。我收到了以下信息。有人可以帮我解释一下这是什么意思吗? - bluepearlsky
ashoke@Dell-3470:~$ sudo service bluetooth status ● 蓝牙服务 - 蓝牙服务Mar 09 15:16:42 Dell-3470 bluetoothd[1141]: 正在启动SDP服务器 Mar 09 15:16:42 Dell-3470 bluetoothd[1141]: 蓝牙管理接口版本1.14> Mar 09 16:35:14 Dell-3470 bluetoothd[1141]: 设置模式失败:失败 (0x03) Mar 09 16:35:59 Dell-3470 bluetoothd[1141]: 设置模式失败:失败 (0x03) Mar 09 16:36:01 Dell-3470 bluetoothd[1141]: 设置模式失败:失败 (0x03) Mar 09 16:36:04 Dell-3470 bluetoothd[1141]: 设置模式失败:失败 (0x03) lines 1-20/20 (END) - bluepearlsky
这个答案对我来说是正确的。我想知道它是否有效,它说是的,我认为这回答了我的问题。谢谢你的帮助 :) - Barra

另一种方法是使用命令hciconfig。它会清晰地列出接口,并通过标记"RUNNING"或"DOWN"显示它们的当前状态。

rfkill 会显示网络设备的列表以及它们的开关状态。


使用BlueZ:使用bluetoothctl(交互式蓝牙控制工具),它提供了一个终端,可以使用show和其他命令。
[bluetooth]# help
Menu main:
Available commands:
-------------------
advertise                        Advertise Options Submenu
scan                             Scan Options Submenu
gatt                             Generic Attribute Submenu
list                             List available controllers
show [ctrl]                      Controller information
select <ctrl>                    Select default controller
devices                          List available devices
paired-devices                   List paired devices
system-alias <name>              Set controller alias
reset-alias                      Reset controller alias
power <on/off>                   Set controller power
pairable <on/off>                Set controller pairable mode
discoverable <on/off>            Set controller discoverable mode
discoverable-timeout [value]     Set discoverable timeout
agent <on/off/capability>        Enable/disable agent with given capability
default-agent                    Set agent as the default one
advertise <on/off/type>          Enable/disable advertising with given type
set-alias <alias>                Set device alias
scan <on/off>                    Scan for devices
info [dev]                       Device information
pair [dev]                       Pair with device
trust [dev]                      Trust device
untrust [dev]                    Untrust device
block [dev]                      Block device
unblock [dev]                    Unblock device
remove <dev>                     Remove device
connect <dev>                    Connect device
disconnect [dev]                 Disconnect device
menu <name>                      Select submenu
version                          Display version
quit                             Quit program
exit                             Quit program
help                             Display help about this program
export                           Print environment variables

使用bluez-toolsbt-*apropos bt-)像bt-device这样的蓝牙设备管理器。

谢谢!这也适用于Fedora 37! - Benyamin Limanto