Manual / basename
basename(1)
| BASENAME(1) | General Commands Manual | BASENAME(1) |
NAME
basename - return the last component of a pathname
SYNOPSIS
basename string [ suffix ]
DESCRIPTION
Basename deletes any prefix ending in the last slash (/) character in string, after first stripping trailing slashes, and writes the result to standard output.
If string is empty, an empty line is printed. If string consists entirely of slashes, a single / is printed.
If suffix is given, and it is not identical to the remaining characters of string, and it is a trailing suffix of them, it is also removed. A suffix at least as long as the remaining characters, or an empty suffix, is never removed.
String is text, not a filesystem lookup: no file named by string needs to exist, and none is opened.
FILES
/usr/man/BASENAME this page
SEE ALSO
DIAGNOSTICS
Exit status is 0 on success; 2 on a usage error (wrong number of operands); 1 if the result would not fit basename's own working buffer (96 bytes).
BUGS
This is the POSIX single-string form only. The BSD extensions -a (treat every operand as its own string) and -s suffix are not implemented -- a second operand is always suffix, never a second string.
| September 14, 2026 | maux |