basename cheat-sheet
Β·
145 words
Β·
1 minute read
What is ‘basename’ ? π
basename is one of GNU core utils. It is used to remove leading directory portions from a path.
Common usage patterns π
Show only the file name from a path:
basename path/to/file
for example:
$ basename static/img/logo.png
logo.png
Show only the rightmost directory name from a path:
basename path/to/directory
for example:
$ basename static/img/
img
Show only the file name from a path, with a suffix removed:
basename path/to/file suffix
for example:
$ basename static/img/logo.png .png
logo
For more information, checkout the official documentation: https://www.gnu.org/software/coreutils/manual/html_node/basename-invocation.html .
I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .