BASENAME(1)

๐ŸŽ€ BASENAME(1) ๐ŸŽ€

okay bestie, welcome to basename โ€” a User Commands classic, and honestly? iconic. โœจ


๐Ÿ’– NAME ๐Ÿ’–

basename โ€” strip directory and suffix from filenames. that's it. that's the whole job. and she does it flawlessly. ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

basename NAME [SUFFIX]
basename OPTION... NAME...

two whole modes, pick your fighter. ๐Ÿซถ


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So here's the vibe: basename prints NAME with any leading directory components removed. just straight up yeets the whole path prefix. bye. ๐Ÿšฎ

And if you specified a trailing SUFFIX, she'll remove that too. double slay. โœจ

real talk though: mandatory arguments to long options are mandatory for short options too. no shortcuts on the shortcuts, bestie. ๐Ÿ’€

โœจ the options, one by one โœจ

  • -a, --multiple โ€” support multiple arguments and treat each as a NAME. plural girlies rise ๐Ÿ™ˆ
  • -s, --suffix=SUFFIX โ€” remove a trailing SUFFIX; implies -a. yes she does it all by herself, no extra flag needed ๐Ÿ’…
  • -z, --zero โ€” end each output line with NUL, not newline. for the chaotic gremlins who need NUL-separated output ๐Ÿ“
  • --help โ€” display this help and exit. she's helpful AND humble ๐Ÿ˜ญ
  • --version โ€” output version information and exit. main character moment ๐Ÿ‘‘

๐ŸŒˆ EXAMPLES ๐ŸŒˆ

these are literally so good, look:

basename /usr/bin/sort          -> "sort"
basename include/stdio.h .h     -> "stdio"
basename -s .h include/stdio.h  -> "stdio"
basename -a any/str1 any/str2   -> "str1" followed by "str2"

see how -s .h and the plain positional .h do the exact same thing?? lowkey the same energy. and -a just eats a whole list of them and spits out "str1" followed by "str2". ate. ๐Ÿ”ฅ


๐Ÿ’œ AUTHOR ๐Ÿ’œ

Written by David MacKenzie. thank you king, we owe you everything ๐Ÿซถ


๐Ÿ› REPORTING BUGS ๐Ÿ›

found something cursed? tell the people:


Copyright ยฉ 2026 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.

This is free software: you are free to change and redistribute it.

There is NO WARRANTY, to the extent permitted by law. fr fr, no cap, don't come for them if it breaks ๐Ÿ˜ญ

๐Ÿ”— SEE ALSO ๐Ÿ”—

Full documentation <https://www.gnu.org/software/coreutils/basename> or available locally via: info '(coreutils) basename invocation'


and that's the whole page bestie!! ๐ŸŽ€โœจ this was GNU coreutils 9.12, dated September 2026 โ€” manual page BASENAME(1), aka the cutest little path-stripper in the whole toolkit. go forth and strip. ๐Ÿ’–๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from