{
    "mode": "info",
    "parameter": "basename",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/basename/json",
    "generated": "2026-11-10T06:38:23Z",
    "sections": {
        "File: coreutils.info,  Node: basename invocation,  Next: dirname invocation,  Up: File name manipulation": {
            "content": "",
            "subsections": [
                {
                    "name": "18.1 'basename': Strip directory and suffix from a file name",
                    "content": "'basename' removes any leading directory components from NAME.\nSynopsis:\n\nbasename NAME [SUFFIX]\nbasename OPTION... NAME...\n\nIf SUFFIX is specified and is identical to the end of NAME, it is\nremoved from NAME as well.  Note that since trailing slashes are removed\nprior to suffix matching, SUFFIX will do nothing if it contains slashes.\n'basename' prints the result on standard output.\n\nTogether, 'basename' and 'dirname' are designed such that if 'ls\n\"$name\"' succeeds, then the command sequence 'cd \"$(dirname \"$name\")\";\nls \"$(basename \"$name\")\"' will, too.  This works for everything except\nfile names containing a trailing newline.\n\nPOSIX allows the implementation to define the results if NAME is\nempty or '//'.  In the former case, GNU 'basename' returns the empty\nstring.  In the latter case, the result is '//' on platforms where // is\ndistinct from /, and '/' on platforms where there is no difference.\n\nThe program accepts the following options.  Also see *note Common\noptions::.  Options must precede operands.\n\n'-a'\n'--multiple'\nSupport more than one argument.  Treat every argument as a NAME.\nWith this, an optional SUFFIX must be specified using the '-s'\noption.\n\n'-s SUFFIX'\n'--suffix=SUFFIX'\nRemove a trailing SUFFIX.  This option implies the '-a' option.\n\n'-z'\n'--zero'\nOutput a zero byte (ASCII NUL) at the end of each line, rather than\na newline.  This option enables other programs to parse the output\neven when that output would contain data with embedded newlines.\n\nAn exit status of zero indicates success, and a nonzero value\nindicates failure.\n\nExamples:\n\n# Output \"sort\".\nbasename /usr/bin/sort\n\n# Output \"stdio\".\nbasename include/stdio.h .h\n\n# Output \"stdio\".\nbasename -s .h include/stdio.h\n\n# Output \"stdio\" followed by \"stdlib\"\nbasename -a -s .h include/stdio.h include/stdlib.h\n"
                }
            ]
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}