包‘package’的文件列表文件缺少最后一个换行符

包‘package’的文件列表文件缺少最后一个换行符

为了解决这个问题我运行了这些命令

sudo mv /var/lib/dpkg/info/<package name>.* /var/www
sudo apt-get install <package name>

但是,当我尝试安装任何新软件包或使用以下命令进行升级时,它会给出其他软件包的错误。

什么原因导致了这个问题?我该如何解决?

$ sudo apt-get dist-upgrade
dpkg: warning: files list file for package 'libexpat1:amd64' missing;
 assuming package has no files currently installed
dpkg: warning: files list file for package 'base-passwd' missing;
 assuming package has no files currently installed
dpkg: warning: files list file for package 'bash' missing;
 assuming package has no files currently installed
dpkg: warning: files list file for package 'debconf' missing;
 assuming package has no files currently installed
dpkg: warning: files list file for package 'dash' missing;
 assuming package has no files currently installed   
dpkg: warning: files list file for package 'coreutils' missing;
 assuming package has no files currently installed
dpkg: warning: files list file for package 'python3-software-properties' missing;
 assuming package has no files currently installed
dpkg: warning: files list file for package 'software-properties-common' missing;
 assuming package has no files currently installed
dpkg: unrecoverable fatal error, aborting: 
 files list file for package 'libcap-ng0:amd64' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
  lxd lxd-client open-iscsi openssl tmux tzdata unattended-upgrades
7 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/9806 kB of archives.
After this operation, 604 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Preconfiguring packages ...
dpkg: warning: files list file for package 'libexpat1:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'base-passwd' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'bash' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'debconf' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'dash' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'coreutils' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'base-files' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'diffutils' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'python3-software-properties' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'ncurses-bin' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'software-properties-common' missing; assuming package has no files currently installed
dpkg: unrecoverable fatal error, aborting:
 files list file for package 'libcap-ng0:amd64' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

$ sudo apt-get install --reinstall base-passwd
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 7 not upgraded.
Need to get 0 B/47.2 kB of archives.
After this operation, 0 B of additional disk space will be used.
Preconfiguring packages ...
dpkg: warning: files list file for package 'libexpat1:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'base-passwd' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'bash' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'debconf' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'dash' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'coreutils' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'base-files' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'diffutils' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'python3-software-properties' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'ncurses-bin' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'software-properties-common' missing; assuming package has no files currently installed
dpkg: unrecoverable fatal error, aborting:
 files list file for package 'libcap-ng0:amd64' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

$ sudo chmod -R a+r /var/lib/dpkg/info
$ cd /var/lib/dpkg/info

/var/lib/dpkg/info$ sudo mv libcap-ng0\:amd64.
libcap-ng0:amd64.list      libcap-ng0:amd64.md5sums   libcap-ng0:amd64.shlibs    libcap-ng0:amd64.triggers

/var/lib/dpkg/info$ sudo mv libcap-ng0\:amd64.
libcap-ng0:amd64.list      libcap-ng0:amd64.md5sums   libcap-ng0:amd64.shlibs    libcap-ng0:amd64.triggers

/var/lib/dpkg/info$ sudo mv libcap-ng0\:amd64.* /var/www/html/

/var/lib/dpkg/info$ sudo apt-get install --reinstall libcap-ng0:amd64
Reading package lists... Done
Building dependency tree
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 7 not upgraded.
Need to get 11.1 kB of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://ap-south-1.ec2.archive.ubuntu.com/ubuntu bionic/main amd64 libcap-ng0 amd64 0.7.7-3.1 [11.1 kB]
Fetched 11.1 kB in 0s (39.2 kB/s)
dpkg: warning: files list file for package 'libexpat1:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'base-passwd' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'bash' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'debconf' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'dash' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'coreutils' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'base-files' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'diffutils' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'python3-software-properties' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'libcap-ng0:amd64' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'ncurses-bin' missing; assuming package has no files currently installed
dpkg: warning: files list file for package 'software-properties-common' missing; assuming package has no files currently installed
dpkg: unrecoverable fatal error, aborting:
 files list file for package 'libcom-err2:amd64' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

我从 /var/lib/dpkg/info 文件夹中删除了 libcap-ng0:amd64 文件,然后尝试重新安装它,但现在它为其他软件包提供了错误,并为 libcap-ng0 提供了警告。
其他软件包也出现了同样的情况。

答案1

以下是修复此问题的分步说明,该问题似乎是与这些包相关的 .list 文件中的文件损坏:

  1. 验证.list 文件是否充满垃圾:

cat /var/lib/dpkg/info/<name-of-package>.list

  1. 删除损坏的 .list 文件:

sudo rm /var/lib/dpkg/info/<name-of-package>.list

  1. 运行该包的重新安装(将显示警告,但应该重新安装):

sudo apt install <name-of-package> --reinstall

如果发生在你身上的事情和我的情况一样,每次运行这个程序时,它都会遇到另一个损坏的 .list 文件,你必须逐步检查许多步骤才能修复系统。如果你有很多步骤,那么第三步是可选的——只需sudo apt upgrade在最后运行一个步骤,它就会重新安装你需要的一切。

答案2

从:apt-get dpkg 错误:文件列表文件...缺少最后的换行符 - LinuxQuestions.org

好吧,在 freenode 的 #debian 的大力帮助下,我找到了解决方案(感谢 justin!!):

文件/var/lib/dpkg/info/smbfs.列表已损坏,全是二进制垃圾。不知道怎么会这样,但事实就是如此。所以贾斯汀建议我删除该文件(实际上,我移动了它)——瞧,apt 警告我找不到 smbfs 的文件列表,但至少我可以apt-get remove smbfs --purge 再次安装它(apt-get install smbfs)——这太不可思议了!

答案3

如果你像我一样在多台机器上遇到 50-80 个损坏的文件,那么手动方法将是一项无休止的任务,所以这是我对这个问题的看法(在 Ubuntu 20.04 上测试)。这基本上是 yourcomputergenius 的自动化版本回答

cd /var/lib/dpkg/info/; \
for i in *; do \
  if (file $i|grep -P '(?<!__DAMAGED:)[\s]data$'); then \
    sudo mv -v "$i" "$i__DAMAGED"; \
  fi; \
done; \
ls *__DAMAGED | cut -d'.' -f1 - | uniq | xargs -I'{}' sudo apt-get install {} --reinstall

它能做什么:

  • 检查目录中的所有文件
  • __DAMAGED通过附加到文件名来重命名所有具有二进制内容的文件
  • 然后:
    • 整理所有损坏的文件
    • 提取文件名的包名称
    • 删除重复的包名称
    • 然后将剩余列表提供给apt重新安装受影响的软件包

我希望它能够帮助遇到此问题的任何人!

答案4

cd /var/lib/dpkg/info/; 
for i in *; do 
  if (file $i|grep -P '(?<!__DAMAGED:)[\s]data$'); then 
    sudo mv -v "$i" "${i}__DAMAGED"; 
  fi; 
done; 
ls *__DAMAGED | cut -d'.' -f1 - | uniq | xargs -I'{}' sudo apt-get install {} --reinstall

它只是@Gergely Lukacsy 提到的相同代码,但纠正了一些错误。

相关内容