basename

From Wikipedia, the free encyclopedia

Template:Short description

Page Module:Infobox/styles.css has no content.

basename
Initial releaseJanuary 1979; 47 years ago (1979-01)
Template:Infobox software/simple
Written inC
EnginePage Template:Plainlist/styles.css has no content.Template:EditAtWikidata
Operating systemUnix, Unix-like, IBM i, Plan 9, Inferno
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3+
Plan 9: MIT License
WebsiteScript error: No such module "WikidataIB".
RepositoryPage Template:Plainlist/styles.css has no content.

Script error: No such module "Check for conflicting parameters".

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

Page Template:Reflist/styles.css has no content.

  1. ^ Template:Man
  2. ^ Template:Man
  3. ^ Template:Man
  4. ^ Page Module:Citation/CS1/styles.css has no content."CoreUtils for Windows". Archived from the original on 2025-07-30. Retrieved 2025-08-09.
  5. ^ Page Module:Citation/CS1/styles.css has no content."Native Win32 ports of some GNU utilities". Archived from the original on 2006-02-09. Retrieved 2020-07-25.
  6. ^ Page Module:Citation/CS1/styles.css has no content.IBM. "IBM System i Version 7.2 Programming Qshell" (PDF). IBM. Archived (PDF) from the original on 2020-09-18. Retrieved 2020-09-05.

Page Module:Side box/styles.css has no content.Page Template:Sister project/styles.css has no content.

Lua error in package.lua at line 80: module 'Module:Navbox/configuration' not found. Template:Core Utilities commands Template:Plan 9 commands