12

When I execute less package.rpm, less shows me all sorts of meta info about the package. What is less exactly doing - does it have built in code to be able to extract meta info, or is an rpm structured in a way that the first part just looks like a text file?

I would assume the former, since head is not so helpful here. But to get to the real question: If I would like to grep through this meta data less showing me, how can I accomplish this?

24

If you browse through the less man page, you'll notice less has an INPUT PREPROCESSOR feature.

echo $LESSOPEN to view the location of this preprocessor, and use less/vim/cat to view its contents.

On my machine this preprocessor is /usr/bin/lesspipe.sh and it includes the following for rpms:

*.rpm) rpm -qpivl --changelog -- "$1"; handle_exit_status $?

In effect, less hands off openning the file to rpm, and shows you the pagination of its output.

Obviously, to grep through this info, simply grep the output of rpm directly:

grep "foo" < <(rpm -qpivl --changelog -- bar.rpm)

Or in general (thanks OrangeDog)

grep "foo" < <(lesspipe.sh bar.rpm)

Note: $LESSOPEN Does not simply hold the location of lesspipe.sh - it begins with a | and ends with a %s so invoking it directly would result in errors.

  • 1
    Why not grep "foo" < <($LESSOPEN bar.rpm)? Or maybe even just $LESSOPEN bar.rpm | grep "foo". – jpmc26 Jun 7 '16 at 20:30
4

If I would like to grep through this meta data less showing me, how can I accomplish this?

very simply; if you want to grep on "Version" for example:

less your.rpm | grep "Version"

Note that less is using the rpm command; so better skip using less; and use rpm commands; like:

rpm -qip /path/to/uninstalled/rpm
rpm -qi installed.rpm

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.