Software:Basename
| Initial release | January 1979 |
|---|---|
| Written in | C |
| Operating system | Unix, Unix-like, IBM i, Plan 9, Inferno |
| Platform | Cross-platform |
| Type | Command |
| License | coreutils: GPLv3+ Plan 9: MIT License |
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.[1] It first appeared in 4.4BSD.[2] The version in GNU Core Utilities was written by David MacKenzie.[3] The command is available for Windows as part of the GnuWin32 project[4] and UnxUtils[5] and is in IBM i.[6]
Use
The Single UNIX Specification is: 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 /path/to/filename.ext
filename.ext
$ basename /path/to/
to
If the suffix argument is included and matches the end of the last name, then that text is removed from the result.
$ basename /path/to/filename.ext .ext
filename
$ basename /path/to/filename.ext xx
filename.ext
See also
References
- ↑ – Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
- ↑ – FreeBSD General Commands Manual
- ↑ – Linux User's Manual – User Commands
- ↑ "CoreUtils for Windows". https://gnuwin32.sourceforge.net/packages/coreutils.htm.
- ↑ "Native Win32 ports of some GNU utilities". http://unxutils.sourceforge.net/.
- ↑ IBM. "IBM System i Version 7.2 Programming Qshell" (in en). https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_74/rzahz/rzahzpdf.pdf?view=kc.
External links
| The Wikibook Guide to Unix has a page on the topic of: Commands |
- : return non-directory portion of a pathname – Commands & Utilities Reference, The Single UNIX Specification, Issue 7 from The Open Group
- – Linux User Commands Manual
- – OpenBSD General Commands Manual
- – Plan 9 Programmer's Manual, Volume 1
- – Inferno General commands Manual
Template:Core Utilities commands Template:Plan 9 commands
