manpagez: man pages & more
info coreutils
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

18.1 basename: Strip directory and suffix from a file name

basename removes any leading directory components from name. Synopsis:

 
basename name [suffix]

If suffix is specified and is identical to the end of name, it is removed from name as well. Note that since trailing slashes are removed prior to suffix matching, suffix will do nothing if it contains slashes. basename prints the result on standard output.

Together, basename and dirname are designed such that if ‘ls "$name"’ succeeds, then the command sequence ‘cd "$(dirname "$name")"; ls "$(basename "$name")"’ will, too. This works for everything except file names containing a trailing newline.

POSIX allows the implementation to define the results if name is empty or ‘//’. In the former case, GNU basename returns the empty string. In the latter case, the result is ‘//’ on platforms where // is distinct from /, and ‘/’ on platforms where there is no difference.

The only options are ‘--help’ and ‘--version’. See section Common options. Options must precede operands.

An exit status of zero indicates success, and a nonzero value indicates failure.

Examples:

 
# Output "sort".
basename /usr/bin/sort

# Output "stdio".
basename include/stdio.h .h

© manpagez.com 2000-2017
Individual documents may contain additional copyright information.