How to List Files with Case-Insensitive Glob Patterns in zsh/bash: A Guide for Varying String Cases
Introduction
In the world of command-line interfaces, efficiently managing and navigating files is a fundamental skill. One powerful tool at your disposal is glob patterns (or "globs"), which allow you to match filenames using wildcard characters like *, ?, and []. However, a common frustration arises when dealing with files that have inconsistent capitalization—think Report.pdf, report.PDF, and REPORT.pdf in the same directory. By default, most shells (including bash and zsh) treat glob patterns as case-sensitive, meaning a pattern like *.pdf would only match filenames with exactly lowercase .pdf extensions, missing variations like .PDF or .Pdf.
This guide will demystify case-insensitive globbing in bash and zsh, walking you through how to match files regardless of letter case, advanced techniques, troubleshooting, and best practices. Whether you’re a system administrator, developer, or casual terminal user, mastering case-insensitive globs will save you time and reduce errors when working with mixed-case filenames.