Basename

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by imported>Stevebroshar at 21:04, 18 May 2025 (See also: use Annotated link|). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Short description Template:Lowercase Script error: No such module "Infobox".Template:Template other Script error: No such module "Check for unknown parameters".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]

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 /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

References

<templatestyles src="Reflist/styles.css" />

  1. basename – Shell and Utilities Reference, The Single UNIX Specification, Version 5 from The Open Group
  2. basename(1) – FreeBSD General Commands Manual
  3. basename(1) – Linux User Manual – User Commands
  4. CoreUtils for Windows
  5. Native Win32 ports of some GNU utilities

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

External links

Template:Sister project

Script error: No such module "Navbox". Template:Plan 9 commands Template:Core Utilities commands