誤刪dpkg的/var/lib/dpkg/info文件夾的解決辦法 zhuan

  
 
今天安裝軟件時時,出現這樣的錯誤提示:E: Sub-process /usr/bin/dpkg returned an error code (1)
 
上網查解決方案,被網上誤導,一不當心誤刪了dpkg的info文件夾,以後在使用apt-get 或者 dpkg命令老是提示
 
「dpkg:警告:沒法找到軟件包 ******* 的文件名列表文件,現假定該軟件包目前沒有任何文件被安裝在系統裏」
 
上網查了一下,info文件夾保存各個軟件的配置文件列表,真是粗枝大葉啊。
 
試了不少網上傳說的方法都很差用,只好祭出谷歌神器,終於在國外的一個文章中找到了解決方案
 
執行下面的腳本
 
#!/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"
 
原理是從新 下載全部安裝過的軟件包,而後從中提取文件列表信息複製到info文件夾裏。
 
執行完畢後提示x11-common有空文件列表,緣由不明,只能執行替換法了,從別的ubuntu上拷貝了x11-common的文件,
 
可是依然提示dpkg警告,例如chrome的,對於這些軟件只好手動安裝了,手動從新安裝chrome和 WPS以後問題解決
 
apt-get和dpkg終於沒有警告了。雖然問題解決,也不知道是否解決完全,暫時就這樣吧,若是在有問題只好重裝了,哇咔咔~
相關文章
相關標籤/搜索