basename flags & options

Basic usage

Strip the directory path, returning just the filename.

basename /usr/local/bin/python3

Remove suffix

Pass a suffix as the second argument to strip it.

basename /home/user/report.pdf .pdf

-s, --suffix

Explicitly specify a suffix to remove.

basename -s .tar.gz archive.tar.gz

-a, --multiple

Handle multiple paths at once.

basename -a /usr/bin/git /usr/bin/curl /usr/bin/wget

-z, --zero

Separate output with NUL instead of newlines. Useful with xargs -0.

basename -az /path/to/file1 /path/to/file2