{
    "mode": "man",
    "parameter": "dirname",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/dirname/1/json",
    "generated": "2026-06-13T21:54:42Z",
    "synopsis": "dirname [OPTION] NAME...",
    "sections": {
        "NAME": {
            "content": "dirname - strip last component from file name\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "dirname [OPTION] NAME...\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Output each NAME with its last non-slash component and trailing slashes removed; if NAME con‐\ntains no /'s, output '.' (meaning the current directory).\n",
            "subsections": [
                {
                    "name": "-z --zero",
                    "content": "end each output line with NUL, not newline\n\n--help display this help and exit\n",
                    "flag": "-z",
                    "long": "--zero"
                },
                {
                    "name": "--version",
                    "content": "output version information and exit\n",
                    "long": "--version"
                }
            ]
        },
        "EXAMPLES": {
            "content": "dirname /usr/bin/\n-> \"/usr\"\n\ndirname dir1/str dir2/str\n-> \"dir1\" followed by \"dir2\"\n\ndirname stdio.h\n-> \".\"\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Written by David MacKenzie and Jim Meyering.\n",
            "subsections": []
        },
        "REPORTING BUGS": {
            "content": "GNU coreutils online help: <https://www.gnu.org/software/coreutils/>\nReport any translation bugs to <https://translationproject.org/team/>\n",
            "subsections": []
        },
        "COPYRIGHT": {
            "content": "Copyright © 2020 Free Software Foundation, Inc.  License GPLv3+: GNU GPL version 3  or  later\n<https://gnu.org/licenses/gpl.html>.\nThis  is free software: you are free to change and redistribute it.  There is NO WARRANTY, to\nthe extent permitted by law.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "basename(1), readlink(1)\n\nFull documentation <https://www.gnu.org/software/coreutils/dirname>\nor available locally via: info '(coreutils) dirname invocation'\n\n\n\nGNU coreutils 8.32                          January 2026                                  DIRNAME(1)",
            "subsections": []
        }
    },
    "summary": "dirname - strip last component from file name",
    "flags": [
        {
            "flag": "-z",
            "long": "--zero",
            "arg": null,
            "description": "end each output line with NUL, not newline --help display this help and exit"
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "output version information and exit"
        }
    ],
    "examples": [
        "dirname /usr/bin/",
        "-> \"/usr\"",
        "dirname dir1/str dir2/str",
        "-> \"dir1\" followed by \"dir2\"",
        "dirname stdio.h",
        "-> \".\""
    ],
    "see_also": [
        {
            "name": "basename",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/basename/1/json"
        },
        {
            "name": "readlink",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/readlink/1/json"
        }
    ],
    "tldr": {
        "source": "official",
        "description": "Remove trailing filename portion from a path.",
        "examples": [
            {
                "description": "Calculate the parent directory of a given path",
                "command": "dirname {{path/to/file_or_directory}}"
            },
            {
                "description": "Calculate the parent directory of multiple paths",
                "command": "dirname {{path/to/file_or_directory1 path/to/file_or_directory2 ...}}"
            },
            {
                "description": "Delimit output with a NUL character instead of a newline (useful when combining with `xargs`)",
                "command": "dirname {{-z|--zero}} {{path/to/file_or_directory1 path/to/file_or_directory2 ...}}"
            }
        ]
    }
}