0

I'm trying to use dpkg -l with grep to list all the download files starting with the letter "a":

dpkg -l | grep "a*"

However, it just printed the contents of the files instead of finding a file starting with the letter "a".

I have thought about using find but still can't do it, any clues how to solve this?

2 Answers 2

0

How can I list all the download files start with "a" using dpkg?

You need to use dpkg-query instead of dpkg, for example:

dpkg-query -l 'a*'

dpkg-query is a tool to show information about packages listed in the dpkg database.

-l, --list [package-name-pattern...]

List all known packages matching one or more patterns, regardless of their status, which includes any real or virtual package referenced in any dependency relationship field (such as Breaks, Enhances, etc.).

...

For example, this will list all package names starting with libc6:

dpkg-query -l 'libc6*'

Source: dpkg-query(1) - Linux manual page

0

$ dpkg -l | grep -E '^.. +a.*'

Why is that so?

First grep -E allows to use a regexp and here the portion between the single quotes is one way to express your wish in a regexp.

^ - do the following at the beginning of each line.
.. - "skip" the first two characters (match anything)
+ - require one space, allow any more of spaces skip them.
a - the a requirement
.* - allow zero or more of any other characters.

... and all this due to how the output of dpkg -l looks; the first ten lines are:

$ dpkg -l | head -n 10
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                          Version                                  Architecture Description
+++-=============================================-========================================-============-================================================================================
ii  accountsservice                               23.13.9-2ubuntu6                         amd64        query and manipulate user account information
ii  acl                                           2.3.2-1build1                            amd64        access control list - utilities
ii  adduser                                       3.137ubuntu1                             all          add and remove users and groups
ii  adwaita-icon-theme                            46.0-1                                   all          default icon theme of GNOME
ii  alsa-base                                     1.0.25+dfsg-0ubuntu7                     all          ALSA driver configuration files

More on regex'es: https://www.rexegg.com/regex-quickstart.php

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .