Forrest logo
back to the basename tool

basename:tldr:bb58c

basename: Show only the file name from a path, with a suffix removed.
$ basename ${filename} ${suffix}
try on your machine

The basename command is used to output the filename portion of a given path, removing any leading directory components. It can also remove a specified suffix from the filename.

In the command basename ${filename} ${suffix}, ${filename} and ${suffix} are placeholders representing the actual values of the variables.

For example, if filename is set to /home/user/docs/file.txt and suffix is set to .txt, the command basename ${filename} ${suffix} will remove the directory component (/home/user/docs/) and the suffix (.txt) from the filename and output just the base name file.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the basename tool