Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

basename

v(uutils coreutils) 0.8.0
basename [-z] NAME [SUFFIX]
basename OPTION... NAME...

Print NAME with any leading directory components removed If specified, also remove a trailing SUFFIX

Options

--multiple, -a

support multiple arguments and treat each as a NAME

--suffix=<SUFFIX>, -s <SUFFIX>

remove a trailing SUFFIX; implies -a

--zero, -z

end each output line with NUL, not newline

Examples

Show only the file name from a path:

basename {{path/to/file}}

Show only the rightmost directory name from a path:

basename {{path/to/directory}}

Show only the file name from a path, with a suffix removed:

basename {{path/to/file}} {{suffix}}

The examples are provided by the tldr-pages project under the CC BY 4.0 License.

Please note that, as uutils is a work in progress, some examples might fail.