如何修复找不到命令的数据库?

dut*_*hie 3 command-line

我最近安装的 Ubuntu 系统当前存在 command-not-found 钩子问题:

josh@sirius:~$ invalid-command
Unable to open binary database /usr/share/command-not-found/programs.d/i386-main.db: File read error
Unable to open binary database /usr/share/command-not-found/programs.d/i386-multiverse.db: File read error
Unable to open binary database /usr/share/command-not-found/programs.d/i386-restricted.db: File read error
Unable to open binary database /usr/share/command-not-found/programs.d/i386-universe.db: File read error
invalid-command: command not found
Run Code Online (Sandbox Code Playgroud)

我试过重新安装和dpkg-reconfigureing 两者,command-not-found{,-data}但这些似乎没有修复它。删除这些文件是否安全,或者我是否必须运行一些程序来重新创建它们?我应该补充一点,这最初是一个 32 位安装,我在没有格式化磁盘的情况下用 64 位重新安装。

Tom*_*dor 5

20.04.4LTS 上,这对我有帮助:

$ sudo apt install --reinstall command-not-found
Run Code Online (Sandbox Code Playgroud)

-data包已不再存在。

我得到了类似的东西:

$ kbounce
Sorry, command-not-found has crashed! Please file a bug report at:
https://bugs.launchpad.net/command-not-found/+filebug
Please include the following information with the report:

command-not-found version: 0.3
Python version: 3.8.5 final 0
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal
Exception information:

unable to open database file
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/CommandNotFound/util.py", line 23, in crash_guard
    callback()
  File "/usr/lib/command-not-found", line 90, in main
    cnf = CommandNotFound.CommandNotFound(options.data_dir)
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 79, in __init__
    self.db = SqliteDatabase(dbpath)
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 12, in __init__
    self.con = sqlite3.connect(filename)
sqlite3.OperationalError: unable to open database file
Run Code Online (Sandbox Code Playgroud)

现在,我得到:

$ kbounce

Command 'kbounce' not found, but can be installed with:

sudo apt install kbounce
Run Code Online (Sandbox Code Playgroud)

编辑 2020-12-16

重启后问题又回来了。我调试/usr/lib/python3/dist-packages/CommandNotFound/db/db.py并发现以下内容:

$ ls /var/lib/command-not-found/ -l
total 3076
-rw-r----- 1 root root 3141632 gru 16 08:17 commands.db
-rw-r----- 1 root root    3253 gru 16 08:17 commands.db.metadata
Run Code Online (Sandbox Code Playgroud)

所以,数据库在那里,但权限是错误的。

所以我执行了:

$ sudo chmod -R o+r /var/lib/command-not-found/
Run Code Online (Sandbox Code Playgroud)

现在,它再次起作用了。


gei*_*rha 1

64 位版本的数据库文件命名为amd64-*.db,32 位版本的数据库文件命名为i386-*.db。显然,当您应该安装 64 位软件包时,您却安装了 32 位软件包。

这个输出什么?

apt-cache policy command-not-found{,-data}
Run Code Online (Sandbox Code Playgroud)