15 May 2021
Basename is a command that could be used to strip directory and suffix from filenames.
The interesting part is that basename does not check the directory or file existence, so the only side effect is to print out the result :) .
Note: the following examples are based on command man/--help page.
Example of usage could be extract a filename from an absolute path.
$ docker run -it ubuntu /bin/bash
# basename /usr/bin/sort
sort
Example of usage could be exctract file name in the next step rename a file changing its suffix.
$ docker run -it ubuntu /bin/bash
# basename --suffix .h include/stdio.h
stdio
$ docker run -it ubuntu /bin/bash
# basename --suffix .h -a include/stdio.h include/my_file.h
stdio
my_file
basename --help