📜 ⬆️ ⬇️

Clearing the local repository from old packages

I think that the situation when several gigabytes of packets accumulate in the cache is known to many. As well as the standard solution - uninstalling packages
$ apt-get clean
The command will clear the "/ var / cache / apt / archives /" directory, removing everything, and
$ apt-get autoclean
will remove not only the old versions of the local cache packages, but all that are no longer available for download.

However, it is often necessary to remove only obsolete packages, without touching all the others.

When I ran into this problem in my ArchLinux, I immediately wrote a small script in bash, the article about which was recently published.

 #!/bin/bash ##   CACHE_DIR="/var/cache/apt/archives" ##   apt-get #CACHE_DIR="/var/cache/pacman/pkg" ##   pacman' ##    EXT="deb" #EXT="pkg.tar.gz" ##   ArchLinux' ## ,       FILTER="sed s/_[0-9].*_//" #FILTER="sed s/-[0-9].*//" ##    ArchLinux' function remove { echo -e "$1\t\t\t[removed]"; rm -f $1; } cd "$CACHE_DIR"; ##      echo "Changed working dir on `pwd`"; pkgs=(`ls | grep $EXT`); ##    hashs=(`ls | grep $EXT | $FILTER`); ##      pkgsNum=${#pkgs[@]} ##    echo "$pkgsNum files in cache now"; for (( i=0; i<$pkgsNum-1; i++ )); do #echo "cheking package ${pkgs[$i]}..."; for (( j=$i+1; j<${pkgsNum}; j++ )); ##    hashes    do if [ ${hashs[$i]} = ${hashs[$j]} ]; then ##      if [ ${pkgs[$i]} -ot ${pkgs[$j]} ]; then ##      remove ${pkgs[$i]}; break; else remove ${pkgs[$j]}; fi fi done done 

The script searches for duplicate packages and removes everything, except for that, whose creation date is later - it is much easier than comparing package versions.
image
For pacman, the problem described is solved with the help of the utility repo-clean , however the program was created specifically for ArchLinux, albeit in C ++. Therefore
$ yaourt -S repo-clean
You to the console! =)

')

Source: https://habr.com/ru/post/61547/


All Articles