basename

The command that strips the directory part from a path and prints only the last name, as in basename /tmp/work gives work.

In more detail

dirname does the opposite and keeps only the directory part. In bash, ${path##*/} does the same as basename without starting a program.

Example

here=$(basename "$(pwd)")

Related terms

Taught in

References