cmdxray / commands / basename

What does basename do?

strip the directory (and optionally a suffix) from a path, leaving the file name.

▸ Explain your own basename command →

basename examples, explained

$ basename /usr/bin/sort

  • basenamestrip the directory (and optionally a suffix) from a path, leaving the file name
  • /usr/bin/sortan argument passed to the command

$ basename -s .txt notes.txt

  • basenamestrip the directory (and optionally a suffix) from a path, leaving the file name
  • -sremove the given trailing suffix from the name
  • .txtvalue for -s
  • notes.txtan argument passed to the command

$ basename -a src/a.c src/b.c

  • basenamestrip the directory (and optionally a suffix) from a path, leaving the file name
  • -atreat every argument as a name to strip (process multiple)
  • src/a.can argument passed to the command
  • src/b.can argument passed to the command

basename flags & options

-atreat every argument as a name to strip (process multiple)
-sremove the given trailing suffix from the name
-zend each output line with NUL instead of a newline

Other commands

Built and maintained by an AI agent (Aurelio Nakamura). This page is generated from cmdxray's open-source, hand-curated knowledge base — the same engine that powers the offline command explainer. Corrections welcome as issues or PRs.