誤刪dpkg的/var/lib/dpkg/info檔案夾的解決辦法 今天安裝軟體時時,出現這樣的錯誤提示:E: Sub-process /usr/bin/dpkg returned an error code (1) 上網查解決方案,被網上誤導,一不小心誤刪了dpkg的info檔案夾,之後在使用apt-get 或者 dpkg命令總是提示 “dpkg:警告:無法找到軟體包 ******* 的檔案名稱列表檔案,現假定該軟體包目前沒有任何檔案被安裝在系統裡” 上網查了一下,info檔案夾儲存各個軟體的設定檔列表,真是粗心大意啊。 試了很多網上傳說的方法都不好用,只好祭出Google神器,終於在國外的一個文章中找到瞭解決方案 執行下面的指令碼 #!/bin/bashset -e # Clean out /var/cache/apt/archivesapt-get clean# Fill it with all the .debs we needapt-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/*.debdo # 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 DEBIANdonermdir "$DIR" 原理是重新下載所有安裝過的軟體包,然後從中提取檔案清單資訊複製到info檔案夾裡。 執行完畢後提示x11-common有空檔案清單,原因不明,只能執行替換法了,從別的ubuntu上拷貝了x11-common的檔案, 但是依然提示dpkg警告,例如chrome的,對於這些軟體只好手動安裝了,手動重新安裝chrome和WPS之後問題解決 apt-get和dpkg終於沒有警告了。雖然問題解決,也不知道是否解決徹底,暫時就這樣吧,如果在有問題只好重裝了,哇哢哢~