The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.
Difference between revisions of "Package:Coreutils/basename"
(Information about what the command does, how to use it, and other resources available about the command.) |
m (Added a space between a "#" and "b") |
||
Line 17: | Line 17: | ||
{{console|desc=|body= | {{console|desc=|body= | ||
###i##basename -a /home/user/directory/file1 /home/user/file2 /bin/executable | ###i## basename -a /home/user/directory/file1 /home/user/file2 /bin/executable | ||
}} | }} | ||
The above returns {{f|file1 file2 executable}}. | The above returns {{f|file1 file2 executable}}. |
Latest revision as of 19:43, June 1, 2015
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.