The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Package:Coreutils/basename
The basename binary serves the function of finding the basename in a linux filesystem directory string. Such strings are made up of a dirname and a basename. For example, given the string /home/username/Documents/file
, the basename is file
and the dirname is /home/username/Documents
. If you need to find the basename of a path, the basename
binary can be very useful. In its most basic form, the command outputs the basename of one path. For example:
root # basename /usr/src/linux
returns the string linux
.
When dealing with files that end in a suffix, such as .c
or .py
, for example, it can be nice to removing the suffix when running basename
. This can be accomplished by running basename
with the -s
flag:
root # basename -s .py /home/user/amazingpython.py amazingpython.py
The above command returns the string amazingpython
.
Finally, when working with lists of paths to find the basename of, it is necessary to invoke basename with the -a
flag:
root #basename -a /home/user/directory/file1 /home/user/file2 /bin/executable
The above returns file1 file2 executable
.
Other resources
For more information about basename
consider reading the basename(1)
and basename(3)
man pages.