I have a directory list of debs with different versions. My requirement is to find packages with matching version.

here is what i tried till now

ls debs/* | grep 1.1.16 | egrep -e 'Package1|Package2|package3'

This above command only gives me the o/p of Package1.

Tried all the options from here. But none of them helps.

  • What you have should most likely work. Can you show the actual filenames in the debs/ directory?
    – Inian
    Dec 26, 2019 at 11:12

2 Answers 2


First, the regular warning about not parsing ls. That said, assuming your files are named sanely, you could do:

ls debs/*1.1.16* | grep -E 'Package1|Package2|package3'

The only difference here is that I'm avoiding the 1st grep, which isn't needed since you can directly pass a glob pattern to ls. Then, instead of the deprecated egrep, I'm using grep -E which is the same thing.

However, this is essentially the same as your command. If it didn't work, then you don't have matching files:

$ ls debs/
1.1.16.Package3  Package1.1.1.160  Package1.1.2.16  Package2.1.1.16
$ ls debs/*1.1.16* | grep -E 'Package1|Package2|package3'

As expected, that shows the two matching files. And this is exactly what your command would have printed as well:

$ ls debs/* | grep 1.1.16 | egrep -e 'Package1|Package2|package3'

Note that since the package3 is lowercase (p instead of P) in the grep pattern, the file 1.1.16.Package3 is not shown.


There is a way to do it without paring ls output.

for package in debs/*Package1*${version}* \
               debs/*Package2*${version}* \
  action with $package;

This way shell will expand the glob and iterate through matching files. In case no file matches provided patterns, the script will simply skip the loop without any error.

Or try find:

find debs/ \( -name "*Package1*${version}*" -o -name "*Package2*${version}*" -o -name "*package3*${version}*" \)

You must log in to answer this question.

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