basename - Return non-directory portion of path name

Synopsis

basename string [suffix]

Description

You can use basename to delete any prefix ending with the last slash (/) character present in string, and a suffix, if specified. The resulting filename is written to standard output. The string is processed using the following rules:

Exit Status

Related information

Examples
  1. Set the shell variable FOO to "trail".
    FOO=$(basename /usr/bin/trail)
    
  2. Return the last part of the path "/usr/bin/this_test" with the "test" suffix removed.
    basename /usr/bin/this_test test