Skip to main content
added 252 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

I'm interpreting the "and" used in the question as a strict "logical and", i.e. as "find files whose names match both *abc* and *out".

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*out

or

$ find . -type f -name "*abc*out"

for example.

The pattern *abc*.out*abc*out would match any name containing the string abc and then ending in out.

If no file matches the pattern, the pattern will be left unexpanded. If that happens, ls will get the pattern *abc*out as the argument rather than a valid filename, and will complain about ls: cannot access *abc*out: No such file or directory.

To make bash display an error about not being able to expand a file globbing pattern rather than passing the unexpanded pattern to ls, set the failglob shell option:

bash-4.4$ ls *abc*out
ls: *abc*out: No such file or directory

bash-4.4$ shopt -s failglob

bash-4.4$ ls *abc*out
bash: no match: *abc*out

I'm interpreting the "and" used in the question as a strict "logical and", i.e. as "find files whose names match both *abc* and *out".

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*out

or

$ find . -type f -name "*abc*out"

for example.

The pattern *abc*.out would match any name containing the string abc and then ending in out.

I'm interpreting the "and" used in the question as a strict "logical and", i.e. as "find files whose names match both *abc* and *out".

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*out

or

$ find . -type f -name "*abc*out"

for example.

The pattern *abc*out would match any name containing the string abc and then ending in out.

If no file matches the pattern, the pattern will be left unexpanded. If that happens, ls will get the pattern *abc*out as the argument rather than a valid filename, and will complain about ls: cannot access *abc*out: No such file or directory.

To make bash display an error about not being able to expand a file globbing pattern rather than passing the unexpanded pattern to ls, set the failglob shell option:

bash-4.4$ ls *abc*out
ls: *abc*out: No such file or directory

bash-4.4$ shopt -s failglob

bash-4.4$ ls *abc*out
bash: no match: *abc*out
added 144 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

I'm interpreting the "and" used in the question as a strict "logical and", i.e. as "find files whose names match both *abc* and *out".

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*.out*abc*out

or

$ find . -type f -name "*abc*.out""*abc*out"

for example.

The pattern *abc*.out would match any name containing the string abc and then ending in .out.

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*.out

or

$ find . -type f -name "*abc*.out"

for example.

The pattern *abc*.out would match any name containing the string abc and then ending in .out.

I'm interpreting the "and" used in the question as a strict "logical and", i.e. as "find files whose names match both *abc* and *out".

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*out

or

$ find . -type f -name "*abc*out"

for example.

The pattern *abc*.out would match any name containing the string abc and then ending in out.

Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

You may use multiple wildcards in one filename globbing pattern:

$ ls *abc*.out

or

$ find . -type f -name "*abc*.out"

for example.

The pattern *abc*.out would match any name containing the string abc and then ending in .out.