A bash loop, for pacman

So long as I am mentioning rather esoteric bash solutions to even more esoteric file management problems, here’s one just for Arch Linux.

I’ve been transforming my Debian-based system into a ConnochaetOS-based one, and wanted to strip out a lot — a lot — of packages in one fell swoop.

pacman didn’t like my primitive attempts with wildcards though, and so as a means to yank anything that contained a particular string — like xf86, for example — I did this:

for i in `pacman -Q | grep xf86 | cut -d' ' -f-1` ; do pacman -Rcsn ${i} ; done

grep strains through pacman’s list of installed packages, and gives the list that includes anything in xf86.

Of course, pacman’s output includes version numbers, so those are trimmed off with cut, setting the delimiter to a single space.

Not great, not fancy, but for the most part, a solution.

5 thoughts on “A bash loop, for pacman

  1. Garrett

    What about… `pacman -Rcsn $(pacman -Qsq xf86)`? The q option gets rid of the version numbers.

    Reply
  2. anon

    Was about to suggest the same thing as Garrett, they both do the same thing although plain old pacman should be a bit faster (probably not noticable anyway).

    To add to the above, another good one to run when cleaning up an arch box is:

    pacman -Rcsn $(pacman -Qdtq)

    Pretty much the equivalent of debian’s:
    apt-get autoremove && apt-get autoclean

    Reply
  3. Buffalo Pete

    Very nice, I’ve wanted to do just this on occasion before. And nicely adaptable too; to install all packages containing string FOO:

    $ for i in `pacman -Ss | grep FOO | cut -d’ ‘ -f-1` ; do pacman -S ${i} ; done

    Reply
  4. Ryan Doenges

    the best choice there would be to say `pacman -Qsq` but if you are going to use cut, a quicker solution would be `awk {print $1}`

    Reply

Leave a reply to Buffalo Pete Cancel reply