Skip to content

I'd like to grep through pacman -Q

As title says, I would like to use grep with the output of pacman -Q to get the following packages (and their versions):

  • kernel

  • grub

  • systemd

  • gnome

  • nvidia

Can anyone point me to the right direction please?

EDIT: Thanks for the help guys! Here is my script (it's still a work-in-progress) https://github.com/bill-mavromatis/arch-discover/blob/master/discover.sh Eventually I want to grab the output of the script and either put it on a conky config, or maybe generate an SVG for a cool-looking wallpaper. Thanks again.

Edited 6 Apr 2017. We only hold this version.

1 points22 comments
Open on Reddit
About this post
Posted
Archived
Edited
Score
1 · 100% up
Kind
Text
ID
63ry81

Author

5
posts
46
comments
2
media
View profile

22 comments

$ pacman -Q linux
linux 4.10.1-1
7 points

Yeah, I'm not sure why OP wants to involve grep here:

$ pacman -Q linux grub systemd ...

already prints the exact info (name + version) that OP is requesting.

5 points

Yep, I'm stupid I should have said I was looking for a way to pipe out the version separately. In hindsight, maybe not even that would be necessary but oh well, at least it was a learning experience... I'm actually very new to arch so it didn't even occur to me that you can add many packages after pacman -Q =/

2 points
pacman -Si {linux,grub,systemd,gnome,nvidia} | egrep 'Name|Version'
4 points

Wow awesome!!! That's exactly what I was looking for! Thanks.

Edit: on second look, -Qi is closer to what I wanted because I wanna check the local installed packages. Still, works great. Now I'm just adding commands on top of the bash script such as:

strings /sbin/init |   awk 'match($0, /(upstart|systemd|sysvinit)/) { print substr($0, RSTART, RLENGTH);exit; }'

to query which init, DE, wm, graphics etc are running first. Then after I get the right packages, I will place the variable names inside the brackets of your command. Thanks a lot!

2 points

TIL egrep is awesome.

1 points

You can also use regular (pun intended) grep with grep 'Name\|Version', but yes, it's convenient to not have to escape meta-characters.

2 points

In addition, the variant programs egrep and fgrep are the same as grep -E and grep -F, respectively. These variants are deprecated, but are provided for backward compatibility.

From: Manual page egrep(1)

1 points

You could also just do

 pacman -Si linux grub systemd gnome nvidia | grep -E 'Name|Version'

(also replaced the egrep with grep -E)

1 points

What is your end goal? Do you want to know the versions of the packages?

4 points

Yes. Ultimately I would like to have a script that queries all your important system software so would output:

  • Your bootloader is: grub 2.0.0-rc2. Your init system is: systemd 232-8. Your login manager is: lightdm 1.22. Your DE is: GNOME 3.22.2. Your kernel is linux 4.10.6. Your graphics driver is nvidia 375.39.

And possibly expand that a bit more later (maybe add a nice GUI, and also have a changelog highlights next to each package). But I know that's too much to ask (unless you can point me to something that is already out there), so I just want a starting point, so probably grepping from pacman -Q is a good start. It's something I want for me, but maybe it's useful for others too.

2 points

You might want to look into just calling libalpm, maybe through pyalpm.

import pyalpm
handle = pyalpm.Handle("/", "/var/lib/pacman")
db = handle.get_localdb()
print(db.get_pkg('systemd').version) # => 232-8
4 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.