commands

basename — extract final path component

Manipulates path text, not the filesystem. Prints the final path component after removing trailing slash characters as applicable and optionally removing a matching suffix. Examples assume a fresh chapter files lab.

Formal Syntax & Structure

linux syntaxlinux
basename NAME [SUFFIX]

Parameters & Attributes

NameTypeDescription
NAMEoperandPath text
SUFFIXoperandOptional suffix to remove

Return Value

text and exit status

Prints the final path component, with an optional matching suffix removed. GNU basename returns 0 on successful text processing; this is not a filesystem existence test.

Working Example

Example Snippetlinux
basename "notes/daily report.txt"
Linux Reference