On Unix-like operating systems, the basename command strips directory information and suffixes from file names.

This page covers the GNU/Linux version of basename.

Description

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

  • Description
  • Syntax
  • Options
  • Examples
  • Related commands
  • Linux commands help

Syntax

basename NAME [SUFFIX]

basename OPTION… NAME…

Options

Examples

basename /usr/bin/sort

Outputs the string “sort”.

basename include/stdio.h .h

Outputs the string “stdio”.

basename -s .h include/stdio.h

basename -a any/str1 any/str2

Outputs the string “str1” followed by the string “str2”.

expr — Evaluate arguments as an expression.