Listing Directories 00‑12 Using Bash extglob Pattern
This article explains how to list directory names ranging from 00 to 12 in a log folder by enabling Bash's extglob option and applying a regular‑expression‑style pattern with the ls command.
A log directory contains subfolders named 00, 01, 02 … 31, and the task is to display only the folders for the first twelve days (00‑12) using a pattern on the file names.
shopt -s extglob ls -al +(0[0-9]|1[0-3])
Explanation
Works in Bash only.
Typical shell globbing uses simple wildcard semantics, not full regular‑expression semantics.
Enabling extglob switches globbing to extended pattern (regex‑like) semantics.
The syntax +(pattern) matches one or more occurrences of the given pattern.
Author: He Weiping, Qunar Travel Division, senior search and database researcher, former Yahoo China search engineer, with extensive experience in search, distributed systems, databases, and cluster design.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.