I want to get the result of rpm -qa | grep something
and then run the result I got rpm -ql result-i-got
, and all in one line.
I have found this to work:
rpm -ql $(rpm -qa | grep something)
I wonder, is there any better or even different way of piping this result to get the same result of what I wrote above? Thanks.
xargs
are made for that:
rpm -qa | grep something | xargs rpm -ql
You can actually provide wildcard arguments to rpm -qa
; this avoids the need to pipe to another command so instead of rpm -qa | grep something
, you can use
rpm -qa '*something*'
Use single or double quotes to prevent the shell from expanding the asterisk as a shell globbing pattern.
Example:
$ rpm -qa '*vim*'
vim-enhanced-7.0.109-7.2.el5
vim-minimal-7.0.109-7.2.el5
vim-common-7.0.109-7.2.el5
The above command can be combined with the -l
option to list the files in the relevant packages.
rpm -qal '*vim*'
One problem with this command is that if more than one package is returned, it’s not clear which files belong to to which package as the package name is not printed. To include the package name in the output, you could add the --queryformat
option to have finer control over how information is printed. E.g., the following example prints the name of the package, underlined by a row of hyphen-minus symbols, followed by the list of files provided by that package:
rpm -qal --qf "\n%{NAME}\n--------\n" '*vim*'
The rpm
man page has more information on customising the output of the command.
If you find yourself using this command often, you could turn it into an alias:
alias rpmlist='rpm -qal --qf "\n%{NAME}\n--------\n"'
and use it like so
rpmlist '*vim*' | less
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With