注意:

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Package:Coreutils/basename

From Funtoo
< Package:Coreutils
Revision as of 19:51, May 31, 2015 by Duncan.britton (talk | contribs) (Information about what the command does, how to use it, and other resources available about the command.)
Jump to navigation Jump to search

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.