coreutils: basename invocation
1
1 18.1 ‘basename’: Strip directory and suffix from a file name
1 ============================================================
1
1 ‘basename’ removes any leading directory components from NAME.
1 Synopsis:
1
1 basename NAME [SUFFIX]
1 basename OPTION... NAME...
1
1 If SUFFIX is specified and is identical to the end of NAME, it is
1 removed from NAME as well. Note that since trailing slashes are removed
1 prior to suffix matching, SUFFIX will do nothing if it contains slashes.
1 ‘basename’ prints the result on standard output.
1
1 Together, ‘basename’ and ‘dirname’ are designed such that if ‘ls
1 "$name"’ succeeds, then the command sequence ‘cd "$(dirname "$name")";
1 ls "$(basename "$name")"’ will, too. This works for everything except
1 file names containing a trailing newline.
1
1 POSIX allows the implementation to define the results if NAME is
1 empty or ‘//’. In the former case, GNU ‘basename’ returns the empty
1 string. In the latter case, the result is ‘//’ on platforms where // is
1 distinct from /, and ‘/’ on platforms where there is no difference.
1
11 The program accepts the following options. Also see ⇒Common
options. Options must precede operands.
1
1 ‘-a’
1 ‘--multiple’
1 Support more than one argument. Treat every argument as a NAME.
1 With this, an optional SUFFIX must be specified using the ‘-s’
1 option.
1
1 ‘-s SUFFIX’
1 ‘--suffix=SUFFIX’
1 Remove a trailing SUFFIX. This option implies the ‘-a’ option.
1
1 ‘-z’
1 ‘--zero’
1 Output a zero byte (ASCII NUL) at the end of each line, rather than
1 a newline. This option enables other programs to parse the output
1 even when that output would contain data with embedded newlines.
1
1 An exit status of zero indicates success, and a nonzero value
1 indicates failure.
1
1 Examples:
1
1 # Output "sort".
1 basename /usr/bin/sort
1
1 # Output "stdio".
1 basename include/stdio.h .h
1
1 # Output "stdio".
1 basename -s .h include/stdio.h
1
1 # Output "stdio" followed by "stdlib"
1 basename -a -s .h include/stdio.h include/stdlib.h
1