You are here: >

Linux and Unix basename command

basename commandAbout basename
basename syntax
basename examples
Related commands
Linux and Unix main page

About basename

basename strips directory information and suffixes from filenames.

Description

basename prints filename NAME with any leading directory components removed. It can optionally also remove any trailing suffix.

basename syntax

basename NAME [SUFFIX]
basename OPTION... NAME... 

Options

-a, --multiple

support multiple arguments and treat each as a NAME.

-s, --suffix=SUFFIX

remove a trailing suffix SUFFIX, such as a file extension.

-z, --zero

separate output with NUL rather than a newline.

--help

display help information and exit.

--version

output version information and exit.

basename examples

basename /usr/bin/sort

Outputs the string "sort".

basename include/stdio.h .h

Outputs the string "stdio".

basename -s .h include/stdio.h

Outputs the string "stdio".

basename -a any/str1 any/str2

Outputs the string "str1" followed by the string "str2".

expr — Evaluate arguments as an expression.