basename

From RaySoft

basename removes any leading directory components from NAME.[1]

If SUFFIX is specified and is identical to the end of NAME, it is removed from NAME as well.[1]

Documentation

Syntax

basename NAME [SUFFIX]

Examples

Remove the directories
basename "${HOME}/tmp/test.txt"

Output:

test.txt
Replace basename using Bashism
file="${HOME}/tmp/test.txt"

echo "${file##*/}"

Output:

test.txt

References