basename(C) 06 January 1993 basename(C) Name basename - remove directory names from pathnames Syntax basename string [ suffix ] Description The basename command deletes any prefix ending in ``/'' and the suffix (if present in string) from string, and prints the result on the standard output. The result is the ``base'' name of the file, that is, the filename without any preceding directory path and without an extension. It is used inside substitution marks (` `) in shell procedures to con- struct new filenames. The related command dirname deletes the last level from string and prints the resulting path on the standard output. Examples The following command displays the filename memos on the standard output: basename /usr/johnh/memos.old .old The following shell procedure, when invoked with the argument /usr/src/cmd/cat.c, compiles the named file and moves the output to a file named cat in the current directory: cc $1 mv a.out `basename $1 .c` See also dirname(C) and sh(C). Standards conformance basename is conformant with X/Open Portability Guide, Issue 3, 1989.