BASENAME(1)

πŸ“¦
version 9.10 Β· 5 versions
, in ubuntu stonking

πŸ’– BASENAME β€” the basename(1) girlies' guide πŸ’–

okay so bestie, welcome to basename β€” the GNU coreutils glow-up that takes a whole dramatic file path and hands you just the pretty little name at the end. she's simple, she's iconic, she's been carrying dirname(1)'s sister act since forever. let's get into it πŸŽ€


✨ NAME ✨

basename β€” strip directory and suffix from filenames πŸ¦‹


🌸 SYNOPSIS 🌸

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

πŸ’… DESCRIPTION πŸ’…

Print NAME with any leading directory components removed. If you say so, she'll also remove a trailing SUFFIX. that's it. that's the whole vibe. no cap. 😌

πŸ’‘ friendly reminder bestie: Mandatory arguments to long options are mandatory for short options too. so like, don't skip the value on -s, she needs it fr fr.

🫢 OPTIONS 🫢

  • -a, --multiple β€” support multiple arguments and treat each as a NAME πŸ‘―β€β™€οΈ (yes queen, she can handle a whole group chat at once)
  • -s, --suffix=SUFFIX β€” remove a trailing SUFFIX; implies -a ⚠️ (so this one auto-unlocks the multiple-args mode, sneaky but cute)
  • -z, --zero β€” end each output line with NUL, not newline 🚫 (for when you want your pipeline to be Null-separated, iykyk)
  • --help β€” display this help and exit πŸ™‹β€β™€οΈ
  • --version β€” output version information and exit πŸ‘‘

πŸ“ EXAMPLES πŸ“

here's where she really eats, no crumbs left:

basename /usr/bin/sort
        -> "sort"

directory drama detached, just "sort" remains. periodt.

basename include/stdio.h .h
        -> "stdio"

she took off the include/ and the .h in one go. dual-wielding. iconic. πŸ’–

basename -s .h include/stdio.h
        -> "stdio"

same energy, but now the suffix removal is doing the work itself via -s .h. chef's kiss ✨

basename -a any/str1 any/str2
        -> "str1" followed by "str2"

-a said "I can do both" and she DID. "str1" followed by "str2". 🌈


🌼 AUTHOR 🌼

Written by David MacKenzie. 🫢 thank you for the gift, king.


😭 REPORTING BUGS 😭

found a bug? don't be shy, tell the girlies:


πŸ”₯ SEE ALSO πŸ”₯

  • dirname(1) β€” her sibling. complementary queen πŸ‘‘
  • readlink(1) β€” also does path things, different flavour πŸ’œ

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

Packaged by Ubuntu (9.10-1ubuntu2) πŸ¦‹ 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.

🚨 IMPORTANT bestie: There is NO WARRANTY, to the extent permitted by law. she's free, she's generous, she's not legally responsible for your rm -rf situation. πŸ™ˆ

and that's the tea, babe πŸ΅πŸ’… β€” this whole glow-up came to you from GNU coreutils 9.10, dated August 2026, page BASENAME(1). go strip some directories, you main character πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈ

πŸ“¦ where this page comes from