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.

About these ads

5 Responses to “A bash loop, for pacman”


  1. 1 Garrett 2011/04/01 at 10:29 PM

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

  2. 2 anon 2011/04/02 at 5:04 AM

    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

  3. 3 Kompromized 2011/04/02 at 5:56 AM

    Yes, get rid of as many of those unsigned Arch packages as you can…

  4. 4 Buffalo Pete 2011/04/03 at 1:47 AM

    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

  5. 5 Ryan Doenges 2011/04/17 at 1:27 PM

    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}`


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Welcome!



Visit the Wiki!

Some recent desktops


May 6, 2011
Musca 0.9.24 on Crux Linux
150Mhz Pentium 96Mb 8Gb CF
 


May 14, 2011
IceWM 1.2.37 and Arch Linux
L2300 core duo 3Gb 320Gb

Some recent games


Apr. 21, 2011
Oolite on Xubuntu 11.04
L2300 core duo 3Gb 320Gb

Enter your email address to subscribe to this blog and receive notifications of new posts.

Join 405 other followers

License

This work is licensed under the GNU Free Documentation License. Please see the About page for details.

Blog Stats

  • 3,960,821 hits

Archives


Follow

Get every new post delivered to your Inbox.

Join 405 other followers

%d bloggers like this: