FNMATCH(3P)
π FNMATCH(3P) π
okay bestie, so this is the POSIX Programmer's Manual page for fnmatch, and it's kind of a big deal π«Ά
πΈ PROLOG πΈ
ok so first thing, real talk: this manual page is part of the POSIX Programmer's Manual. but heads up β the Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the deets on Linux behavior), or the interface might not even be implemented on Linux at all. π no cap.
β¨ NAME β¨
fnmatch β match a filename string or a pathname
π SYNOPSIS π
#include <fnmatch.h>
int fnmatch(const char *pattern, const char *string, int flags);
π¦ DESCRIPTION π¦
so the fnmatch() function shall match patterns exactly as described in the Shell and Utilities volume of POSIX.1β2017, Section 2.13.1, Patterns Matching a Single Character, and Section 2.13.2, Patterns Matching Multiple Characters. what it does is it checks the string specified by the string argument to see if it matches the pattern specified by the pattern argument. it's giving vibe check, but for filenames. π
The flags argument shall modify the interpretation of pattern and string. it's the bitwise-inclusive OR of zero or more of the flags defined in <fnmatch.h>. so let's break it down:
- If the
FNM_PATHNAMEflag is set inflags, then a<slash>character ('/') instringshall be explicitly matched by a<slash>inpattern; it shall not be matched by either the<asterisk>or<question-mark>special characters, nor by a bracket expression. If theFNM_PATHNAMEflag is not set, the<slash>character shall be treated as an ordinary character. like, it's just a girl. π - If
FNM_NOESCAPEis not set inflags, a<backslash>character inpatternfollowed by any other character shall match that second character instring. In particular,"\\"shall match a<backslash>instring. Ifpatternends with an unescaped<backslash>,fnmatch()shall return a non-zero value (indicating either no match or an error). IfFNM_NOESCAPEis set, a<backslash>character shall be treated as an ordinary character. π - If
FNM_PERIODis set inflags, then a leading<period>(.) instringshall match a<period>inpattern; as described by rule 2 in the Shell and Utilities volume of POSIX.1β2017, Section 2.13.3, Patterns Used for Filename Expansion, where the location of "leading" is indicated by the value ofFNM_PATHNAME:- If
FNM_PATHNAMEis set, a<period>is "leading" if it is the first character instringor if it immediately follows a<slash>. β - If
FNM_PATHNAMEis not set, a<period>is "leading" only if it is the first character ofstring. β¨
- If
- If
FNM_PERIODis not set, then no special restrictions are placed on matching a period. do what you want, periodt. π
π RETURN VALUE π
If string matches the pattern specified by pattern, then fnmatch() shall return 0. π₯³ If there is no match, fnmatch() shall return FNM_NOMATCH, which is defined in <fnmatch.h>. If an error occurs, fnmatch() shall return another non-zero value. sad girl hours π
π ERRORS π
No errors are defined. iconic, honestly.
The following sections are informative.
π EXAMPLES π
None. bestie we got nothing. π
π APPLICATION USAGE π
The fnmatch() function has two major uses. it could be used by an application or utility that needs to read a directory and apply a pattern against each entry β the find utility is an example of this. it can also be used by the pax utility to process its pattern operands, or by applications that need to match strings in a similar manner. versatile queen. π
The name fnmatch() is intended to imply filename match, rather than pathname match. The default action of this function is to match filename strings, rather than pathnames, since it gives no special significance to the <slash> character. With the FNM_PATHNAME flag, fnmatch() does match pathnames, but without tilde expansion, parameter expansion, or special treatment for a <period> at the beginning of a filename. so like, know the limits. no cap.
π§ RATIONALE π§
This function replaced the REG_FILENAME flag of regcomp() in early proposals of this volume of POSIX.1β2017. It provides virtually the same functionality as the regcomp() and regexec() functions using the REG_FILENAME and REG_FSLASH flags (the REG_FSLASH flag was proposed for regcomp(), and would have had the opposite effect from FNM_PATHNAME), but with a simpler function and less system overhead. glow up, honestly. β¨
π FUTURE DIRECTIONS π
None. the future is... nothing. we love a stable API. π
π₯ SEE ALSO π₯
glob(), Section 2.6, Word Expansions- The Base Definitions volume of POSIX.1β2017,
<fnmatch.h>
π COPYRIGHT π
Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! brought to you by IEEE/The Open Group, 2017, living under the header FNMATCH(3P) β mwah, go match some patterns πβ¨π
π¦ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 Β· custom
- alpine 3.23: man-pages-posix 2017a-r0 Β· custom
- alpine 3.24: man-pages-posix 2017a-r0 Β· custom
- arch rolling: man-pages 6.19-1
- 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-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 Β· SUSE-IEEE
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms