0

Using metacharacters, I need to perform a long listing of all files whose name contains the string foo followed by two digits, then followed by .txt. foo**.txt will not work, obviously. I can't figure out how to do it.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
user2504710
  • 42
  • 1
  • 8

2 Answers2

0

Something like ls foo[0-9][0-9]*.txt of whatever exactly fits your pattern.

Michael Kohl
  • 66,324
  • 14
  • 138
  • 158
0

Use Valid Shell Globbing with Character Class

To find your substring anywhere in a filename like bar-foo12-baz.txt, you need a wilcard before and after the match. You can also use a character class in your pattern to match a limited range of characters. For example, in Bash:

# Explicit character classes.
ls -l *foo[0-9][0-9]*.txt

# POSIX character classes.
ls -l *foo[[:digit:]][[:digit:]]*.txt

See Also

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199