basename
{{Short description|Shell command for extracting the last name from a path}}
{{lowercase}}
{{Infobox software
| name = basename
| logo =
| screenshot =
| screenshot size =
| caption =
| developer =
| released = {{Start date and age|1979|1}}
| latest release version =
| latest release date =
| programming language = C
| operating system = Unix, Unix-like, Plan 9, Inferno
| platform = Cross-platform
| genre = Command
| license = coreutils: GPLv3+
Plan 9: MIT License
| website =
}}
basename
is a shell command for extracting the last name of a file path.
The command was introduced in X/Open Portability Guidelines issue 2 of 1987. It was inherited into the first version of POSIX and the Single Unix Specification.{{man|cu|basename|SUS}} It first appeared in 4.4BSD.{{man|1|basename|FreeBSD}} The version in GNU Core Utilities was written by David MacKenzie.{{man|1|basename|Linux}} The command is available for Windows as part of the GnuWin32 project[http://gnuwin32.sourceforge.net/packages/coreutils.htm CoreUtils for Windows] and UnxUtils.[http://unxutils.sourceforge.net/ Native Win32 ports of some GNU utilities]
Use
The Single UNIX Specification is: {{code|basename path [suffix]}}. The required argument, path
, is a file path string. The second argument, which is optional, is text to remove from the end of the last name if it ends with the text.
Examples
The command reports the last part of a path ignoring any trailing slashes.
$ basename /home/jsmith/base.wiki
base.wiki
$ basename /home/jsmith/
jsmith
If the suffix argument is included and matches the end of the last name, then that text is removed from the result.
$ basename /home/jsmith/base.wiki .wiki
base
$ basename /home/jsmith/base.wiki xx
base.wiki
See also
- {{Annotated link|dirname}}
- {{Annotated link|List of POSIX commands}}
References
{{Reflist}}
External links
{{Wikibooks|Guide to Unix|Commands}}
- {{man|cu|basename|SUS|return non-directory portion of a pathname}}
- {{man|1|basename|Plan 9}}
- {{man|1|basename|Inferno}}
- {{man|1|basename|die.net}}
- {{man|1|basename|OpenBSD}}
{{Unix commands}}
{{Plan 9 commands}}
{{Core Utilities commands}}
Category:Unix SUS2008 utilities