files list file for package '*****' is missing final newline的解决

本文详细介绍了如何解决Ubuntu系统在安装软件时遇到的dpkg错误,特别是当出现‘fileslistfileforpackage'是缺失最终换行符’的问题时。通过执行特定的Python脚本,可以修复dpkg文件中可能存在的错误,从而顺利安装所需软件,如unrar和texlive-base。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

root@ubuntu:/opt# apt-get install unrar
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  unrar
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 0 B/107 kB of archives.
After this operation, 266 kB of additional disk space will be used.
Selecting previously unselected package unrar.
(Reading database ... 90%dpkg: unrecoverable fatal error, aborting:
 files list file for package 'texlive-base' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

root@ubuntu:/opt# 


root@ubuntu:/opt# apt-get install texlive-base --reinstall
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 8 not upgraded.
Need to get 0 B/14.7 MB of archives.
After this operation, 0 B of additional disk space will be used.
Preconfiguring packages ...
(Reading database ... 90%dpkg: unrecoverable fatal error, aborting:
 files list file for package 'texlive-base' is missing final newline
E: Sub-process /usr/bin/dpkg returned an error code (2)

root@ubuntu:/opt# 


参考
http://www.linuxquestions.org/questions/debian-26/apt-get-dpkg-error-5dpkg-788082/
http://ubuntuforums.org/showthread.php?t=1319791

的牛人写了这么一个脚本:

#!/usr/bin/python


# 8th November, 2009
# update manager failed, giving me the error:
#       'files list file for package 'xxx' is missing final newline' for every package.
# some Googling revealed that this problem was due to corrupt files(s) in /var/lib/dpkg/info/
# looping though those files revealed that some did not have a final new line
# this script will resolve that problem by appending a newline to all files that are missing it
# NOTE: you will need to run this script as root, e.g. sudo python newline_fixer.py

import os

dpkg_path = '/var/lib/dpkg/info/'
paths = os.listdir(dpkg_path)
for path in paths:
    path = dpkg_path + path
    f = open(path, 'a+')
    data = f.read()
    if len(data) > 1 and data[-1:] != '\n':
        f.write('\n')
        print 'added newline character to:', path
    f.close()  









root@ubuntu:/home/zhangbin# chmod +x fixAPT.py
root@ubuntu:/home/zhangbin# ./fixAPT.py
./fixAPT.py: line 9: import: command not found
./fixAPT.py: line 11: dpkg_path: command not found
./fixAPT.py: line 12: syntax error near unexpected token `('
./fixAPT.py: line 12: `paths = os.listdir(dpkg_path)'
root@ubuntu:/home/zhangbin# ./fixAPT.py
added newline character to: /var/lib/dpkg/info/texlive-latex-extra-doc.md5sums
added newline character to: /var/lib/dpkg/info/texlive-latex-recommended.md5sums
added newline character to: /var/lib/dpkg/info/bash.preinst
added newline character to: /var/lib/dpkg/info/texlive-base.md5sums
added newline character to: /var/lib/dpkg/info/dictionaries-common.postinst
added newline character to: /var/lib/dpkg/info/texlive-latex-extra.list
added newline character to: /var/lib/dpkg/info/texlive-latex-extra.md5sums
added newline character to: /var/lib/dpkg/info/texlive-latex-recommended.list
added newline character to: /var/lib/dpkg/info/texlive-base.list
added newline character to: /var/lib/dpkg/info/lmodern.md5sums
added newline character to: /var/lib/dpkg/info/texlive-latex-base.md5sums
root@ubuntu:/home/zhangbin# 




root@ubuntu:/home/zhangbin# apt-get install unrar
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  unrar
0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded.
Need to get 0 B/107 kB of archives.
After this operation, 266 kB of additional disk space will be used.
Selecting previously unselected package unrar.
(Reading database ... 247526 files and directories currently installed.)
Unpacking unrar (from .../unrar_1%3a4.0.3-1_i386.deb) ...
(Noting disappearance of texlive-latex-extra, which has been completely replaced.)

Processing triggers for man-db ...
Processing triggers for tex-common ...
Running mktexlsr. This may take some time... done.
Running updmap-sys. This may take some time... done.
Running mktexlsr /var/lib/texmf ... done.
Setting up unrar (1:4.0.3-1) ...
update-alternatives: using /usr/bin/unrar-nonfree to provide /usr/bin/unrar (unrar) in auto mode.
The following package disappeared from your system as
all files have been overwritten by other packages:
  texlive-latex-extra

Note: This is done automatic and on purpose by dpkg.
root@ubuntu:/home/zhangbin# 








评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

等风来不如迎风去

你的鼓励是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值