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. It first appeared in 4.4BSD. The version in GNU Core Utilities was written by David MacKenzie. The command is available for Windows as part of the GnuWin32 project and UnxUtils and is in IBM i.
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.
If the suffix argument is included and matches the end of the last name, then that text is removed from the result.
See also dirname – Shell command for extracting the directory path portion from a path List of POSIX commands
References
External links
basename: return non-directory portion of a pathname – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group basename(1) – Linux User Commands Manual basename(1) – OpenBSD General Commands Manual basename(1) – Plan 9 Programmer's Manual, Volume 1 basename(1) – Inferno General commands Manual