0

I have files:

list-a1.jpg, list-a2.jpg

list-b1.jpg, list-b2.jpg

map-a1.jpg,map-a2.jpg

map-b1.jpg, map-b2.jpg

I want to list them using ls. I want to use regex but I have problem with prefixes. How to specify that my filename should start with "list-" or "map-"? I tried to do:

ls [.map-.][.list-.][a-b][1-2].jpg

but it is not working as expected.

user852
  • 41
  • 1
  • 2
  • 6
  • you could use grep `ls | grep '^(map|list)-[a-b][1-2].jpg'` – Prix Nov 03 '18 at 14:40
  • [List all the files with prefixes from a for loop using Bash](https://stackoverflow.com/q/22365552/608639) and friends. Plenty of questions and answer on sister sites, too. – jww Nov 03 '18 at 17:48

2 Answers2

1

ls accepts multiple file parameters: ls [OPTION]... [FILE]...:

ls list-* map-*

For more control, you could take advantage of bash's curly brace expansion:

ls {list,map}-{a,b}{1,2}.*
steffen
  • 16,138
  • 4
  • 42
  • 81
-1

You could use "extended globbing" - documentation:

shopt -s extglob
ls @(map|list)*
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432