Ask Your Question

dnf search with regular expression query, sorted output?

asked 2015-04-06 13:21:28 -0500

dsvensson gravatar image

updated 2015-04-06 14:27:37 -0500

Coming from Debian and being used to be able to search for packages like:

apt-cache search ^vim

And thus finding all packages that has a name that begins with vim, sorted by package name, is there any similar functionality available that I'm unable to find?

Right now I'm resorting to:

dnf search vim | sort | grep ^vim

..which feels a bit redundant.

edit retag flag offensive close merge delete


Indeed it is; why are you using sort at all? I don't use dnf as yet, but I do know that this will work in yum: yum seaarch vim\* and I see no reason it wouldn't work just as well with dnf.

sideburns gravatar imagesideburns ( 2015-04-06 13:51:51 -0500 )edit

The output is not sorted here at least. An example of the above query, the first 6 packages start with the characters: v.., n.., g.., v.., n.., v.., where the expected order would be g.., n.., n.., v.., v.., v... Non-sorted output makes it harder to find what you're looking for, specially if you recall what an application name begins with.

dsvensson gravatar imagedsvensson ( 2015-04-06 14:04:15 -0500 )edit

I've noticed that "pkcon search" instead of "dnf search" returns the list sorted at least, but according to at least pkcon still lacks regexp matches, and the ticket is from 2010 so it looks like a dead end... and I guess dnf doesn't support it either.

dsvensson gravatar imagedsvensson ( 2015-04-06 14:31:54 -0500 )edit

Using ^vim in your query only gets you packages that start with vim; how are you getting packages who's names start with other letters?

sideburns gravatar imagesideburns ( 2015-04-06 16:18:08 -0500 )edit

By not using grep, only dnf search, the problem was not that I couldn't find packages starting with "vim" in an ordered fashion, but that I had to compose the output via a number of commands, however, the marked answer below explains how dnf is supposed to be used.

dsvensson gravatar imagedsvensson ( 2015-04-08 01:25:48 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-06 19:29:04 -0500

snowolfe gravatar image

updated 2015-04-07 07:48:41 -0500

dnf is (in theory) a drop in replacement for yum, as such the search option searches for ALL instances of the string "vim" in the "package name and description" - it is implicitly *vim*, and case insensitive. Consequently you are seeing package names that may not start with, or even contain vim, but have vim in the description.

This will give you the outcome you desire, all packages that start with vim:

dnf list vim\*

You can further filter by using dnf list available - for uninstalled packages, dnf list installed - for installed packages.

As you may be aware, the backslash \ in front of the asterisk passes the asterisk to dnf rather than * being handled by the shell (bash).

If you want to use more sophisticated regular expressions on the package name pipe the dnf list command through grep for example:

dnf list | grep 'regex'
edit flag offensive delete link more

Question Tools



Asked: 2015-04-06 13:19:00 -0500

Seen: 7,088 times

Last updated: Apr 07 '15