basename /path/to/file.txt

Category: Administration

basename /path/to/file.txt

Print the last path component

basename strips the directory part and prints file.txt, the final component of the path. It is the standard tool for pulling a filename out of a full path in scripts. Pair it with dirname to get the directory half.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.