Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 History  





2 Usage  





3 Examples  





4 See also  





5 References  





6 External links  














basename






العربية
Беларуская
Čeština
Dansk
Deutsch
Ελληνικά
Español
Français

Italiano
Magyar

Polski
Română
Svenska
Українська

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 


basename
Initial releaseJanuary 1979; 45 years ago (1979-01)
Written inC
Operating systemUnix, Unix-like, Plan 9, Inferno
PlatformCross-platform
TypeCommand
Licensecoreutils: GPLv3+
Plan 9: MIT License

basename is a standard computer programonUnix and Unix-like operating systems. When basename is given a pathname, it will delete any prefix up to the last slash ('/') character and return the result. basename is described in the Single UNIX Specification and is primarily used in shell scripts.

History[edit]

basename 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 of basename bundled in GNU coreutils was written by David MacKenzie.[3]

The command is available as a separate package for Microsoft Windows as part of the GnuWin32 project[4] and the UnxUtils collection of native Win32 ports of common GNU Unix-like utilities.[5]

Usage[edit]

The Single UNIX Specification specification for basename is.

basename string [suffix]
string
Apathname
suffix
If specified, basename will also delete the suffix.

Examples[edit]

basename will retrieve the last name from a pathname ignoring any trailing slashes

$ basename /home/jsmith/base.wiki 
base.wiki

$ basename /home/jsmith/
jsmith

$ basename /
/

basename can also be used to remove the end of the base name, but not the complete base name

$ basename /home/jsmith/base.wiki .wiki
base

$ basename /home/jsmith/base.wiki kibase.wi

$ basename /home/jsmith/base.wiki base.wiki
base.wiki

See also[edit]

References[edit]

  1. ^ basename – Shell and Utilities Reference, The Single UNIX Specification, Version 4 from The Open Group
  • ^ basename(1) – FreeBSD General Commands Manual
  • ^ basename(1) – Linux User Manual – User Commands
  • ^ CoreUtils for Windows
  • ^ Native Win32 ports of some GNU utilities
  • External links[edit]


    Retrieved from "https://en.wikipedia.org/w/index.php?title=Basename&oldid=1153579957"

    Categories: 
    Standard Unix programs
    Unix SUS2008 utilities
    Plan 9 commands
    Inferno (operating system) commands
    IBM i Qshell commands
    Hidden categories: 
    Articles with short description
    Short description is different from Wikidata
     



    This page was last edited on 7 May 2023, at 05:30 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki