Ubuntu:files list file for package missing

2017-02-08 Lu Huang 更多博文 » 博客 » GitHub »

原文链接 https://hlthu.github.io/ubuntu/2017/02/08/ubuntu-files-list-file-for-package-missing.html
注:以下为加速网络访问所做的原文缓存,经过重新格式化,可能存在格式方面的问题,或偶有遗漏信息,请以原文为准。


昨天在用sudo apt-get install XXX安装软件包的时候出现了下面所示的错误。

E: Sub-process /usr/bin/dpkg returned an error code (1)

原来是dpkg处于锁定状态,最后无奈吧/usr/lib/dpkg/info目录删除,新建 /usr/lib/dpkg/info。但是接着问题出来了。每次更新按照就会出来一大堆这样的错误!

files list file for package '**' missing; assuming package has no files currently installed

最后Google,找到了这个博客:kubuntu下面files list file for package '**' missing; assuming package has no files currently installed。然后按照该教程顺利地解决了问题,感谢博主。其原理就是自动帮你从新去下载一次以前安装过的包和软件!

具体方法是新建一个脚本文件(.sh),然后输入下面的内容。

#!/bin/bash
set -e

# Clean out /var/cache/apt/archives
apt-get clean
# Fill it with all the .debs we need
apt-get --reinstall -dy install $(dpkg --get-selections | grep '[[:space:]]install' | cut -f1)

DIR=$(mktemp -d -t info-XXXXXX)
for deb in /var/cache/apt/archives/*.deb
do
    # Move to working directory
    cd "$DIR"
    # Create DEBIAN directory
    mkdir -p DEBIAN
    # Extract control files
    dpkg-deb -e "$deb"
    # Extract file list, fixing up the leading ./ and turning / into /.
    dpkg-deb -c "$deb" | awk '{print $NF}' | cut -c2- | sed -e 's/^\/$/\/./' > DEBIAN/list
    # Figure out binary package name
    DEB=$(basename "$deb" | cut -d_ -f1)
    # Copy each control file into place
    cd DEBIAN
    for file in *
    do
        cp -a "$file" /var/lib/dpkg/info/"$DEB"."$file"
    done
    # Clean up
    cd ..
    rm -rf DEBIAN
done
rmdir "$DIR"

并将该文件保存为xxx.sh,然后执行下面的命令即可以修复。

sudo ./xxx.sh