Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Basename
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Shell command for extracting the last name from a path}} {{lowercase}} {{Infobox software | name = basename | logo = | screenshot = | screenshot size = | caption = | developer = | released = {{Start date and age|1979|1}} | latest release version = | latest release date = | programming language = [[C (programming language)|C]] | operating system = [[Unix]], [[Unix-like]], [[Plan 9 from Bell Labs|Plan 9]], [[Inferno (operating system)|Inferno]] | platform = [[Cross-platform]] | genre = [[Command (computing)|Command]] | license = [[coreutils]]: [[GPLv3+]]<br />Plan 9: [[MIT License]] | website = }} '''<code>basename</code>''' is a [[shell (computing)|shell]] [[command (computing)|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>{{man|cu|basename|SUS}}</ref> It first appeared in 4.4BSD.<ref>{{man|1|basename|FreeBSD}}</ref> The version in [[GNU Core Utilities]] was written by David MacKenzie.<ref>{{man|1|basename|Linux}}</ref> The command is available for [[Windows]] as part of the [[GnuWin32]] project<ref>[http://gnuwin32.sourceforge.net/packages/coreutils.htm CoreUtils for Windows]</ref> and [[UnxUtils]].<ref>[http://unxutils.sourceforge.net/ Native Win32 ports of some GNU utilities]</ref> ==Use== The [[Single UNIX Specification]] is: {{code|basename path [suffix]}}. The required argument, <code>path</code>, 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 /home/jsmith/base.wiki base.wiki $ basename /home/jsmith/ jsmith </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 /home/jsmith/base.wiki .wiki base $ basename /home/jsmith/base.wiki xx base.wiki </syntaxhighlight> ==See also== * {{Annotated link|dirname}} * {{Annotated link|List of POSIX commands}} ==References== {{Reflist}} ==External links== {{Wikibooks|Guide to Unix|Commands}} *{{man|cu|basename|SUS|return non-directory portion of a pathname}} *{{man|1|basename|Plan 9}} *{{man|1|basename|Inferno}} *{{man|1|basename|die.net}} *{{man|1|basename|OpenBSD}} {{Unix commands}} {{Plan 9 commands}} {{Core Utilities commands}} [[Category:Standard Unix programs|Basename]] [[Category:Unix SUS2008 utilities]] [[Category:Plan 9 commands]] [[Category:Inferno (operating system) commands]] [[Category:IBM i Qshell commands]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Annotated link
(
edit
)
Template:Code
(
edit
)
Template:Core Utilities commands
(
edit
)
Template:Infobox
(
edit
)
Template:Infobox software
(
edit
)
Template:Lowercase
(
edit
)
Template:Main other
(
edit
)
Template:Man
(
edit
)
Template:Plan 9 commands
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Sister project
(
edit
)
Template:Template other
(
edit
)
Template:Unix commands
(
edit
)
Template:Wikibooks
(
edit
)