11

Fedora documentation says:

5.2. Advanced Searches

If you do not know the name of the package, use the search or provides options. Alternatively, use wild cards or regular expressions with any yum search option to broaden the search critieria.

Well, at first I thought that this is simply wrong or outdated, since no known syntax of regular expressions would work with yum search, but then I found this: yum search [cl-*] for example. But it does something otherworldly. It finds things which have neither "c" nor "l" letters in the name or description. (What I wanted is to find all packages, whose names would be matched by cl-.* regexp.

I also found few people suggesting to pipe yum results to grep, which, of course, solves the problem. But, just on principle, I want to find out what did the thing in the square brackets do. What if yum actually can search by regexp?

12

searching with YUM

You generally don't use any regular expressions (globs) when searching with yum search since the command search is already looking for sub-strings within the package names and their summaries. How do I know this? There's a message that tells you this when you use yum search.

Name and summary matches only, use "search all" for everything.

NOTE: The string [cl-*] is technically a glob in the Bash shell.

So you generally look for fragments of strings that you want with search. The regular expressions come into play when you're looking for particular packages. These are the YUM commands like list and install.

For example:
$ yum list cl-* | expand
Loaded plugins: fastestmirror, langpacks, refresh-packagekit, tsflags
Loading mirror speeds from cached hostfile
 * fedora: mirror.dmacc.net
 * rpmfusion-free: mirror.nexcess.net
 * rpmfusion-free-updates: mirror.nexcess.net
 * rpmfusion-nonfree: mirror.nexcess.net
 * rpmfusion-nonfree-updates: mirror.nexcess.net
 * updates: mirror.dmacc.net
Available Packages
cl-asdf.noarch                  20101028-5.fc19                 fedora          
cl-clx.noarch                   0.7.4-4.3                       home_zhonghuaren
cl-ppcre.noarch                 2.0.3-3.3                       home_zhonghuaren

The only caveat you have to be careful with regexes/globs, is if there are files within your shell that are named such that they too would matchcl-*. In those cases your shell will expand the regex/glob prior to it being presented to YUM.

So instead of running yum list cl-* you'll be running the command yum list cl-file, if there's a file matching the regex/glob cl-*.

For example:
$ ls cl-file
cl-file

$ yum list cl-*
Loaded plugins: fastestmirror, langpacks, refresh-packagekit, tsflags
Loading mirror speeds from cached hostfile
 * fedora: mirror.steadfast.net
 * rpmfusion-free: mirror.nexcess.net
 * rpmfusion-free-updates: mirror.nexcess.net
 * rpmfusion-nonfree: mirror.nexcess.net
 * rpmfusion-nonfree-updates: mirror.nexcess.net
 * updates: mirror.steadfast.net
Error: No matching Packages to list

You can guard against this happening by escaping the wildcard like so:

$ yum list cl-\* | expand
Loaded plugins: fastestmirror, langpacks, refresh-packagekit, tsflags
Loading mirror speeds from cached hostfile
 * fedora: mirror.dmacc.net
 * rpmfusion-free: mirror.nexcess.net
 * rpmfusion-free-updates: mirror.nexcess.net
 * rpmfusion-nonfree: mirror.nexcess.net
 * rpmfusion-nonfree-updates: mirror.nexcess.net
 * updates: mirror.dmacc.net
Available Packages
cl-asdf.noarch                  20101028-5.fc19                 fedora          
cl-clx.noarch                   0.7.4-4.3                       home_zhonghuaren
cl-ppcre.noarch                 2.0.3-3.3                       home_zhonghuaren

So what about the brackets

I suspect you have files in your local directory that are getting matched when you used [cl-*] as an argument to yum search. These files after being matched by the shell, were passed to the yum search command where matches where then found.

For example:
$ ls cl-file
cl-file

$ yum search cl-*
Loaded plugins: fastestmirror, langpacks, refresh-packagekit, tsflags
Loading mirror speeds from cached hostfile
 * fedora: mirror.dmacc.net
 * rpmfusion-free: mirror.nexcess.net
 * rpmfusion-free-updates: mirror.nexcess.net
 * rpmfusion-nonfree: mirror.nexcess.net
 * rpmfusion-nonfree-updates: mirror.nexcess.net
 * updates: mirror.dmacc.net
======================================================================= N/S matched: cl-file =======================================================================
opencl-filesystem.noarch : OpenCL filesystem layout

  Name and summary matches only, use "search all" for everything.

NOTE: The match above was matched against my file's name, cl-file, and not the cl-* as I had intended.

  • Oooh, I see now. Well, that explains it. One nitpicking remark though cl-* isn't a regular expression, it's a glob or whatever it's called. It's a regular language (in Chomskian terms), but we usually say that something is a regular expression if it defines a grammar for regular language (by using at least three basic operations: concatenation, alteration and Kleene star). – wvxvw Sep 12 '14 at 8:00
  • @wvxvw - that's correct. You started with the terminology regex and I just leaned into it 8-). – slm Sep 15 '14 at 19:05
3

Definitely different yum version, using RHEL 6.5 here with yum 3.2.29 Beware:
You should quote the * to not match anything in the current directory via shell globbing ... For more details on that and a practical example, see the later answer: https://unix.stackexchange.com/a/155157/83329

Anyways, just checked again, the only way to actually search effectively with yum search is by yum search all | grep foo as yum search foo gives pretty fuzzy results. But yum list "foo-*" works just as expected, and only result in your case would probably be the package cl-asdf.noarch .

Quickly glancing over related yum bugreports yum search seems to also have other drawbacks: https://bugs.launchpad.net/percona-server/+bug/580336/comments/2

1

Sorry cannot comment yet so have to use an answer.

Did you try yum search cl-* or yum list 'cl-*' ? At least for yum whatprovides */foo it works for searching filenames, although that's a bit of a special case. Otherwise I also often use
yum list all | grep -i foo but beware of the multiline output of yum, grep might only show the first line, so maybe use yum list all | grep -iA1 foo

There are also some useful examples in the man page below "List Options". Additional documentation is also available directly upstream at http://yum.baseurl.org/ e.g. http://yum.baseurl.org/wiki/YumCommands or maybe directly via python: http://yum.baseurl.org/wiki/YumCodeSnippet/YumSearch

  • Did I try yum search cl-*? - yes I did. This finds nothing (maybe different yum version? I'm still using FC18). – wvxvw Sep 12 '14 at 7:42
  • Well, from reading on the intented use case for yum search, combining it with regular expressions/wildcards is double-redundant. yum search already does a fuzzy search, so using wildcards is pretty useless. If you want to constrain your search, use yum list expression or yum list all | grep expression. Otherwise I suggest you open an enhancement request against yum - good luck with that :p – doktor5000 Sep 15 '14 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.