{
    "mode": "info",
    "parameter": "dirname",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/info/dirname/json",
    "generated": "2026-11-15T14:47:53Z",
    "sections": {
        "File: coreutils.info,  Node: dirname invocation,  Next: pathchk invocation,  Prev: basename invocation,  Up: File name manipulation": {
            "content": "",
            "subsections": [
                {
                    "name": "18.2 'dirname': Strip last file name component",
                    "content": "'dirname' prints all but the final slash-delimited component of each\nNAME.  Slashes on either side of the final component are also removed."
                }
            ]
        },
        "If the string contains no slash, 'dirname' prints '.' (meaning the": {
            "content": "current directory).  Synopsis:\n\ndirname [OPTION] NAME...\n\nNAME need not be a file name, but if it is, this operation\neffectively lists the directory that contains the final component,\nincluding the case when the final component is itself a directory.\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\n'//'.  With GNU 'dirname', the result is '//' on platforms where // is\ndistinct from /, and '/' on platforms where there is no difference.\n\nThe program accepts the following option.  Also see *note Common\noptions::.\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 \"/usr/bin\".\ndirname /usr/bin/sort\ndirname /usr/bin//.//\n\n# Output \"dir1\" followed by \"dir2\"\ndirname dir1/str dir2/str\n\n# Output \".\".\ndirname stdio.h\n",
            "subsections": []
        }
    },
    "flags": [],
    "examples": [],
    "see_also": []
}