Basename

From Vero - Wikipedia
Jump to navigation Jump to search

Template:Short description Template:Lowercase Template:Infobox software 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.<ref>Template:Man</ref> It first appeared in 4.4BSD.<ref>Template:Man</ref> The version in GNU Core Utilities was written by David MacKenzie.<ref>Template:Man</ref> The command is available for Windows as part of the GnuWin32 project<ref>CoreUtils for Windows</ref> and UnxUtils<ref>Native Win32 ports of some GNU utilities</ref> and is in IBM i.<ref>Template:Cite web</ref>

Use

The Single UNIX Specification is: <syntaxhighlight lang="text" class="" style="" inline="1">basename path [suffix]</syntaxhighlight>. 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.

<syntaxhighlight lang="console"> $ basename /path/to/filename.ext filename.ext

$ basename /path/to/ to </syntaxhighlight>

If the suffix argument is included and matches the end of the last name, then that text is removed from the result.

<syntaxhighlight lang="console"> $ basename /path/to/filename.ext .ext filename

$ basename /path/to/filename.ext xx filename.ext </syntaxhighlight>

See also

References

Template:Reflist

Template:Sister project

Template:Unix commands Template:Core Utilities commands Template:Plan 9 commands