fnmatch(3)
โจ fnmatch โ bestie edition โจ
okay so real talk, this is from the Library Functions Manual โ it's fnmatch(3) and she is THAT girl of shell wildcard matching. let's get into it ๐
๐ธ NAME ๐ธ
fnmatch โ match filename or pathname.
no cap, that's the whole job. she looks at a string and tells you if it vibes with a pattern. ๐ฆ
๐ LIBRARY ๐
Standard C library: libc, -lc. your fave, literally always there for you ๐ซถ
โจ SYNOPSIS โจ
#include <fnmatch.h>
int fnmatch(const char *pattern, const char *string, int flags);
three args, zero drama. she's lowkey elegant like that ๐
๐ DESCRIPTION ๐
so. the fnmatch() function checks whether the string argument matches the pattern argument โ and that pattern is a shell wildcard pattern (peep glob(7) for the deets, iykyk ๐).
the flags argument is what changes her behavior, and bestie it is the bitwise OR of zero or more of the following flags. zero. or more. you pick, she's flexible ๐
FNM_NOESCAPEโ when this one's set, a backslash is just a regular character doing regular character things, not an escape character. she's retiring, your honor ๐FNM_PATHNAMEโ set this and a slash instringcan only be matched by a slash inpattern. not by an asterisk (*), not by a question mark (?), and not by a bracket expression ([]) that contains a slash. slashes stay exclusive, periodt ๐FNM_PERIODโ set this and a leading period instringhas to be matched exactly by a period inpattern. and what counts as "leading"? a period is leading if it's the first character instring, or if bothFNM_PATHNAMEis set and the period immediately follows a slash. dotfiles are picky, respect her boundaries ๐FNM_FILE_NAMEโ this is a GNU synonym forFNM_PATHNAME. same girl, different name ๐ญFNM_LEADING_DIRโ this one's a GNU extension. set it and the pattern counts as matched if it matches an initial segment ofstringthat is followed by a slash. also important: this flag is mainly for the internal use of glibc and is implemented only in certain cases. so like, don't build your whole personality on it ๐FNM_CASEFOLD/FNM_IGNORECASE(same asFNM_CASEFOLD) โ set this and the pattern is matched case-insensitively. no uppercase slander here, every letter is welcome ๐FNM_EXTMATCHโ a GNU extension. set it and extended patterns are supported โ as introduced by'ksh'and now supported by other shells. the extended format goes like this, where pattern-list is a'|'-separated list of patterns ๐'?(pattern-list)'โ the pattern matches if zero or one occurrences of any of the patterns in the pattern-list match the input string.'*(pattern-list)'โ the pattern matches if zero or more occurrences of any of the patterns in the pattern-list match the input string.'+(pattern-list)'โ the pattern matches if one or more occurrences of any of the patterns in the pattern-list match the input string.'@(pattern-list)'โ the pattern matches if exactly one occurrence of any of the patterns in the pattern-list match the input string.'!(pattern-list)'โ the pattern matches if the input string cannot be matched with any of the patterns in the pattern-list. the hater of the group, and we love her for it ๐โจ
๐ฏ RETURN VALUE ๐ฏ
- Zero if
stringmatchespatternโ slay, we love a clean zero ๐ FNM_NOMATCHif there's no match ๐ญ- another nonzero value if there's an error. so likeโฆ not every nonzero is
FNM_NOMATCH, check before you spiral fr fr
๐งต ATTRIBUTES ๐งต
for an explanation of the terms used in this section, go see attributes(7).
- Interface:
fnmatch() - Attribute: Thread safety
- Value:
MT-Safe env locale
(that was a table in the original, bestie โ we're just vibing in bullets now ๐)
๐ STANDARDS ๐
fnmatch()โ POSIX.1-2008.FNM_CASEFOLD,FNM_IGNORECASEโ POSIX.1-2024.FNM_FILE_NAME,FNM_LEADING_DIRโ GNU.
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
fnmatch()โ POSIX.1-2001, POSIX.2.FNM_CASEFOLDโ has been available on many systems even before POSIX.1-2024. she was an icon before the paperwork caught up, iconic behavior ๐
๐ SEE ALSO ๐
sh(1), glob(3), scandir(3), wordexp(3), glob(7)
and that's the whole page, bestie โ go match some strings, treat backslashes with respect, and don't forget that FNM_LEADING_DIR is glibc-internal and only implemented in certain cases ๐ญ๐
this has been Linux man-pages 6.20, dated 2026-02-08, page fnmatch(3) ๐ธ stay matching, stay MT-Safe ๐ซถโจ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms