I wanted to know the packages which are installed and starting with mos then below command not working.
dpkg -l | grep ^mos*
I wanted to know the packages which are installed and starting with mos then below command not working.
dpkg -l | grep ^mos*
Although
^mos*
is a perfectly cromulent grep Basic regular Expression (BRE), it likely doesn't mean what you think it means. You should also get into the habit of quoting any pattern that you pass to grep, so that the shell does not try to expand it to a list of filenames in the current directory.1*
in a regular expression is a quantifier rather than a wildcard, somos*
meansm
o
then zero or mores
characters. The regex equivalent of the shell wildcard*
would be.*
(any character, zero or more times). However since grep by default outputs the whole line even when the match is partial, a trailing.*
is superfluous -^mos
would do as well as^mos.*
However
^
anchors a regular expression to the start of a line - anddpkg -l
outputs the package's status before its name, so^mos
will never match in this context.You could use
^.. *mos
to match two arbitrary status characters anchored to start-of-line, followed by one or more spaces beforemos
:however I'd suggest using awk instead of grep for this task, since you can match against specific fields ex.
or if you want to output only matching installed packages for example
To get
grep
use regex add-E
switch this way:But this won't give you any results, because
dpkg -l
lines start withii
and other chars.You can try this one: