Files and folders
The basename command
From a full path, shows only the final name of the file or folder.
Syntax
basename <ruta> [sufijo]Copy-ready examples
$ basename /etc/passwdFinal name$ basename /home/alumno/informe.txt .txtRemoving the extensionYou can try them in the browser terminal: it does not touch your computer.
Typical mistakes
- Very useful inside scripts to keep just the file name.
FAQ
Do basename and dirname complement each other?
Yes: one gives the name and the other the folder that holds it.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course