# Zsh Glob Qualifiers

Zsh glob qualifiers are a parenthesized suffix you can append to any glob pattern to filter, sort, or slice the matched files. They're one of zsh's most useful features over bash, and the `(om[1])` pattern in particular solves a common annoyance: picking the most recently created file without knowing its exact name.

## The om[1] pattern

Append `(om[1])` to a glob to get the single newest match:

- `o` — sort the results
- `m` — by modification time, newest first
- `[1]` — take only the first one

```zsh
# open the most recent screenshot
open ~/Screenshots/*.png(om[1])

# pass the newest log file to less
less /var/log/app-*.log(om[1])
```

This eliminates the `ls -t | head -1` dance and works inline — no subshell, no pipe, just a glob with a qualifier.

## Chaining commands with generated files

The article [[zsh-om1-glob-qualifiers|by Adam Johnson]] shows a memray workflow where each command produces a file the next command needs, with an unpredictable PID in the filename:

```zsh
memray run manage.py check \
  && memray flamegraph memray-*.bin(om[1]) \
  && open -a Firefox memray-flamegraph-*.html(om[1])
```

Each step grabs whatever the previous step just created. No manual copy-paste of filenames.

## Other useful qualifiers

Glob qualifiers go well beyond sorting. A few common ones:

| Qualifier | Meaning |
|-----------|---------|
| `.` | regular files only |
| `/` | directories only |
| `@` | symlinks only |
| `om` | sort by modification time (newest first) |
| `On` | sort by name |
| `OL` | sort by size (largest first) |
| `[1,5]` | take matches 1 through 5 |
| `Lm+10` | files larger than 10 MB |
| `mh-1` | modified in the last hour |

Qualifiers combine: `*.log(.om[1]Lm+1)` means "the most recently modified regular file matching `*.log` that's over 1 MB."

## Why this matters

Shell workflows frequently generate files with dynamic names — PIDs, timestamps, UUIDs. The usual workaround is capturing the filename in a variable or piping through `ls -t`. Glob qualifiers let you express "the newest match" directly in the glob itself, which composes better with `&&` chains and keeps the command readable.
