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
| Name | Type | Description |
|---|---|---|
| NAME | operand | Path text |
| SUFFIX | operand | Optional 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"