Difference between revisions of "Package:Coreutils/basename"

From Funtoo
Jump to navigation Jump to search
(Created the page.)
 
(Information about what the command does, how to use it, and other resources available about the command.)
Line 1: Line 1:
This is a test.
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 {{f|/home/username/Documents/file}}, the basename is {{f|file}} and the ''dirname'' is {{f|/home/username/Documents}}. If you need to find the basename of a path, the {{f|basename}} binary can be very useful. In its most basic form, the command outputs the basename of one path. For example:
 
{{console|desc=|body=
###i## basename /usr/src/linux
}}
returns the string {{f|linux}}.
 
When dealing with files that end in a suffix, such as {{f|.c}} or {{f|.py}}, for example, it can be nice to removing the suffix when running {{f|basename}}. This can be accomplished by running {{f|basename}} with the {{f|-s}} flag:
 
{{console|desc=|body=
###i## basename -s .py /home/user/amazingpython.py
amazingpython.py
}}
The above command returns the string {{f|amazingpython}}.
 
Finally, when working with lists of paths to find the basename of, it is necessary to invoke basename with the {{f|-a}} flag:
 
{{console|desc=|body=
###i##basename -a /home/user/directory/file1 /home/user/file2 /bin/executable
}}
The above returns {{f|file1 file2 executable}}.
 
=== Other resources ===
For more information about {{f|basename}} consider reading the {{f|basename(1)}} and {{f|basename(3)}} man pages.

Revision as of 19:51, May 31, 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.