basename is a common program found on Unix systems; typically it is the GNU Project's coreutils version, which is Free software. Given a pathname, it will return the name of the file that the pathname refers to. For example, basename /home/john/pictures/cat.jpg will return "cat.jpg". While this may seem trivial and useless to humans, basename is a useful tool in shell scripts. Filiation of Unix and Unix-like systems Unix (officially trademarked as UNIX®) is a computer operating system originally developed in the 1960s and 1970s by a group of AT&T employees at Bell Labs including Ken Thompson, Dennis Ritchie and Douglas McIlroy. ... GNU (pronounced ) is a computer operating system - consisting of a kernel, libraries, system utilities, compilers, and end-user application software - composed entirely of free software. ... Coreutils is a package of GNU software containing many of the basic tools such as cat, ls, and rm needed for Unix-like operating systems to function. ... This article is about free software as defined by the sociopolitical free software movement; for information on software distributed without charge, see freeware. ... A path is the general form of a file or directory name, giving a files name and its unique location in a file system. ... A shell script is a script written for the shell, or command line interpreter, of an operating system. ...
A related command is dirname, which returns the directory name without the filename. For example, dirname /home/john/pictures/cat.jpg will return "/home/john/pictures"
See Also
dirname: get directory name component of path
External links
asename.1.html b asename(1): strip directory and suffix from filenames – Linuxman page on die.net
The string operand shall be treated as a pathname, as defined in the Base Definitions volume of IEEE Std 1003.1-2001, Section 3.266, Pathname.
The behaviors of basename and dirname have been coordinated so that when string is a valid pathname:
Since the definition of pathname specifies implementation-defined behavior for pathnames starting with two slash characters, this volume of IEEE Std 1003.1-2001 specifies similar implementation-defined behavior for the basename and dirname utilities.