Linux command: base name

Quick startbasenameCommand to return the file name part of the path

Suppose you have a file path, for example/Users/flavio/test.txt.

Run

basename /Users/flavio/test.txt

Will returntext.txtString:

If you runbasenameOn the path string pointing to the directory, you will get the last segment of the path. In this example/Users/flavioIs a directory:

ThisbasenameThis command can be used in Linux, macOS, WSL and wherever you have a UNIX environment

Download mine for freeLinux Command Manual


More cli tutorials: