Forrest logo
back to the basename tool

basename:tldr:9ef07

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

The command basename ${filename} is used to extract the base name (file name and extension) from the given variable or argument filename. Here's how it works:

  • ${filename} represents the variable or argument that holds the file name.
  • The command basename then takes this variable or argument as input.
  • It extracts only the base name of the file, which is the file name without the directory path.
  • The resulting base name is then displayed as the output.

For example, if the variable filename contains the value /path/to/file.txt, running basename ${filename} will output file.txt (removing the /path/to/ part).

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