Negated Globs With extglob

Use !(pattern) and @(a|b) extended patterns to filter filenames.

macOSbashshellscriptingLow risk
Run shopt -s extglob then ls !(*.log) to list everything except log files.

01Command

Command
$ shopt -s extglob; ls !(*.log)

02What it does

Extended globbing adds negated and grouped patterns to ordinary globs, so filtering a directory by extension needs no pipeline. It is a precise, shell-native way to select files for batch operations, something a file dialog cannot express.

03Risk

RiskLow risk
RequirementsmacOS default zsh/bash (bash 3.2+; some features need bash 4+ via Homebrew)
CompatibilitymacOS with bash 3.2+ (GNU bash 4+ via Homebrew for advanced features)
!Warning: extglob must be enabled before use and is incompatible with other pattern options in some shells.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer