pathname(7)

๐Ÿ’– pathname(7) โ€” a little chat about pathnames ๐Ÿ’–

okay bestie, gather round, we're talking pathname(7) from the Miscellaneous Information Manual and honestly? it's giving foundational. it's giving "everything you love is built on this." let's go ๐Ÿฆ‹


โœจ NAME โœจ

pathname, filename โ€” how pathnames get encoded and interpreted. that's the whole vibe. ๐Ÿ’…


๐ŸŒธ DESCRIPTION ๐ŸŒธ

so like, some system calls let you pass a pathname as a parameter. iconic of them. but when you're writing code that deals with pathnames, there's a whole situation you gotta respect:

  • there are kernel-space requirements that you must comply with (no negotiating, bestie, this is non-negotiable)
  • and there are user-space requirements that you should comply with (soft launch rules, but still, do them)

๐ŸŽ€ the C string thing (iykyk)

the kernel stores pathnames as C strings โ€” that means sequences of non-null bytes, terminated by a null byte. periodt.

and there are a few general rules that apply to all pathnames:

  • the last byte in the sequence needs to be a null byte โ€” that's the closer, the mic drop, the end of the sentence ๐ŸŒ™
  • any other bytes in the sequence need to be non-null bytes โ€” no sneak-attack nulls in the middle, we don't do that here ๐Ÿ’€
  • a 0x2F byte ('/') is always interpreted as a directory separator, and it literally cannot be part of a filename. sorry. it's taken.
  • a pathname can be at most PATH_MAX bytes long (see limits.h(0p)). and if your pathname is longer than PATH_MAX bytes? not me panicking, because you can split it into multiple smaller pathnames and open it piecewise using openat(2). slay, we love a workaround ๐Ÿซถ
  • a filename can be at most a certain number of bytes long, and that number is filesystem-specific (see _PC_NAME_MAX in fpathconf(3)). for maximum portability, programs should be able to handle filenames that are as long as the relevant filesystems will allow. and โ€” also for maximum portability โ€” programs and users should limit the length of their own pathnames to NAME_MAX bytes (see limits.h(0p)). yes, both. the code and the human. we're all in this together ๐Ÿ˜ญ

๐Ÿฆ‹ further restrictions (the plot thickens)

some filesystems or APIs may apply further restrictions, like:

  • requiring shorter filenames
  • restricting the allowed bytes in a filename

so like, don't assume your fave filesystem's rules are everyone's rules. vibe check your filesystem first ๐Ÿ’ซ

and for maximum interoperability, programs and users should also limit the characters they use for their own pathnames to characters in the POSIX Portable Filename Character Set. that's the safe little garden of characters, bestie. stay in the garden ๐ŸŒธ


๐ŸŒˆ VERSIONS ๐ŸŒˆ

POSIX.1-2024 encourages implementations to disallow creation of filenames containing new-line characters.

Linux does not follow this, and allows using new-line characters. not Linux being the rebellious main character ๐Ÿ˜Œ๐Ÿ’…


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘

go read them, they're all part of the lore ๐Ÿ”ฅ


mwah ๐Ÿ’‹ that's the page. sourced from Linux man-pages 6.20, dated 2026-02-08 โ€” love her, cite her, she ate ๐Ÿ’–๐ŸŽ€โœจ

๐Ÿ“ฆ 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms