{
    "mode": "man",
    "parameter": "tempfile",
    "section": "1",
    "url": "https://www.chedong.com/phpMan.php/man/tempfile/1/json",
    "generated": "2026-06-15T11:12:56Z",
    "synopsis": "tempfile  [-d  DIR]  [-p  STRING]  [-s  STRING] [-m MODE] [-n FILE] [--directory=DIR] [--pre‐\nfix=STRING] [--suffix=STRING] [--mode=MODE] [--name=FILE] [--help] [--version]",
    "sections": {
        "NAME": {
            "content": "tempfile - create a temporary file in a safe manner\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "tempfile  [-d  DIR]  [-p  STRING]  [-s  STRING] [-m MODE] [-n FILE] [--directory=DIR] [--pre‐\nfix=STRING] [--suffix=STRING] [--mode=MODE] [--name=FILE] [--help] [--version]\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "tempfile creates a temporary file in a safe manner.  It uses mkstemps(3) to choose  the  name\nand opens it with ORDWR | OCREAT | OEXCL.  The filename is printed on standard output.\n\nThe directory in which to create the file might be searched for in this order:\n\na) In case the environment variable TMPDIR exists and contains the name of an appropriate di‐\nrectory, that is used.\n\nb) Otherwise, if the --directory argument is specified and appropriate, it is used.\n\nc) Otherwise, Ptmpdir (as defined in <stdio.h>) is used when appropriate.\n\nd) Finally an implementation-defined directory (/tmp) may be used.\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-d, --directory",
                    "content": "Place the file in DIR.\n",
                    "flag": "-d",
                    "long": "--directory"
                },
                {
                    "name": "-m, --mode",
                    "content": "Open the file with MODE instead of 0600.\n",
                    "flag": "-m",
                    "long": "--mode"
                },
                {
                    "name": "-n, --name",
                    "content": "Use FILE for the name instead of tempnam(3).  The options -d, -p, and -s  are  ignored\nif this option is given.\n",
                    "flag": "-n",
                    "long": "--name"
                },
                {
                    "name": "-p, --prefix",
                    "content": "Use up to five letters of STRING to generate the name.\n",
                    "flag": "-p",
                    "long": "--prefix"
                },
                {
                    "name": "-s, --suffix",
                    "content": "Generate the file with STRING as the suffix.\n\n--help Print a usage message on standard output and exit successfully.\n",
                    "flag": "-s",
                    "long": "--suffix"
                },
                {
                    "name": "--version",
                    "content": "Print version information on standard output and exit successfully.\n",
                    "long": "--version"
                }
            ]
        },
        "RETURN VALUES": {
            "content": "An exit status of 0 means the temporary file was created successfully.  Any other exit status\nindicates an error.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Exclusive creation is not guaranteed when creating files on NFS partitions.  tempfile  cannot\nmake temporary directories.  tempfile is deprecated; you should use mktemp(1) instead.\n",
            "subsections": []
        },
        "EXAMPLE": {
            "content": "#!/bin/sh\n#[...]\nt=$(tempfile) || exit\ntrap \"rm -f -- '$t'\" EXIT\n#[...]\nrm -f -- \"$t\"\ntrap - EXIT\nexit\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "tempnam(3), mktemp(1)\n\n\n\nDebian                                       27 Jun 2012                                 TEMPFILE(1)",
            "subsections": []
        }
    },
    "summary": "tempfile - create a temporary file in a safe manner",
    "flags": [
        {
            "flag": "-d",
            "long": "--directory",
            "arg": null,
            "description": "Place the file in DIR."
        },
        {
            "flag": "-m",
            "long": "--mode",
            "arg": null,
            "description": "Open the file with MODE instead of 0600."
        },
        {
            "flag": "-n",
            "long": "--name",
            "arg": null,
            "description": "Use FILE for the name instead of tempnam(3). The options -d, -p, and -s are ignored if this option is given."
        },
        {
            "flag": "-p",
            "long": "--prefix",
            "arg": null,
            "description": "Use up to five letters of STRING to generate the name."
        },
        {
            "flag": "-s",
            "long": "--suffix",
            "arg": null,
            "description": "Generate the file with STRING as the suffix. --help Print a usage message on standard output and exit successfully."
        },
        {
            "flag": "",
            "long": "--version",
            "arg": null,
            "description": "Print version information on standard output and exit successfully."
        }
    ],
    "examples": [
        "#!/bin/sh",
        "#[...]",
        "t=$(tempfile) || exit",
        "trap \"rm -f -- '$t'\" EXIT",
        "#[...]",
        "rm -f -- \"$t\"",
        "trap - EXIT",
        "exit"
    ],
    "see_also": [
        {
            "name": "tempnam",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/tempnam/3/json"
        },
        {
            "name": "mktemp",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/mktemp/1/json"
        }
    ],
    "tldr": {
        "source": "not_found",
        "examples": []
    }
}