{
    "mode": "man",
    "parameter": "tmpreaper",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/tmpreaper/8/json",
    "generated": "2026-10-06T04:03:21Z",
    "synopsis": "tmpreaper  [-htvfmMsaT]  [--help]  [--test]  [--verbose]  [--force] [--delay=x] [--runtime=x]\n[--showdeleted]  [--ctime]   [--mtime]   [--mtime-dir]   [--symlinks]   [--all]   [[--protect\n'<shellpattern>']...]  <timespec> <dirs>...",
    "sections": {
        "NAME": {
            "content": "tmpreaper - removes files which haven't been accessed for a period of time\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "tmpreaper  [-htvfmMsaT]  [--help]  [--test]  [--verbose]  [--force] [--delay=x] [--runtime=x]\n[--showdeleted]  [--ctime]   [--mtime]   [--mtime-dir]   [--symlinks]   [--all]   [[--protect\n'<shellpattern>']...]  <timespec> <dirs>...\n\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "tmpreaper recursively searches for and removes files and empty directories which haven't been\naccessed  for  a  given number of seconds.  Normally, it's used to clean up directories which\nare used for temporary holding space, such as \"/tmp\".  Please read the  WARNINGS  section  of\nthis manual.\n\nWhen  changing  directories,  tmpreaper is very sensitive to possible race condition security\nexploits[1], and will exit with an error if one is detected.  It  does  not  follow  symbolic\nlinks  in  the  directories it's cleaning (even if a symbolic link is given as its argument),\nnever performs chdir(\"..\"), will not switch file systems, and only removes empty  directories\nand  regular  files. Unless your machine is one with lots of relatively untrusted users, such\nas an ISP or school, you don't need this program; `find ... -exec rm ...' works just as  well\nwhen you don't have to be concerned about people trying to exploit the race condition on you.\n\ntmpreaper  will  stop  itself after almost one minute with an appropriate warning message, as\nattempts to keep it running long enough so that it runs in parallel with another instance  of\nitself  may also lead to possible vulnerabilities. Normally, tmpreaper won't need that amount\nof time.  If your system is so slow that it does,  try  to  configure  things  so  that  this\ndoesn't  happen.  As  a  last resort, the --runtime=x option can be used to set the number of\nseconds after which the timeout occurs; the default setting is 55 seconds.\n\ntmpreaper dates files by their atime, not their mtime, unless you select the --mtime  option.\nIf files aren't being removed when ls -l implies they should be, use stat(1) or ls --time=ac‐\ncess to examine the file's atime and see if that helps to explain the problem.\n\nAdditionally,  tmpreaper  can be instructed to also check the ctime (inode change time, which\nis updated e.g. when the file is created or permissions are changed). This is primarily  use‐\nful  when tmpreaper is used to clean up directories that are accessible as a Samba share; DOS\n(and Windows) PCs preserve the mtime and the atime when copying to a new file, so that it ap‐\npears that the newly created file is old.  tmpreaper will remove such files if the  atime  is\nbeyond  the  removal  time,  even though they were just created. This is avoided by using the\n--ctime option.\n\nAs testing the contents of subdirectories will update those directories' atime, empty  direc‐\ntories won't be removed. To circumvent this problem you can use the --mtime-dir option, which\nwill  switch on mtime checking for directories only. Using --mtime-dir in addition to --mtime\ndoesn't do anything useful.\n\nThe <timespec> parameter defines the age threshold for removing files. If the file  has  not\nbeen  accessed for <timespec>, it becomes eligible for removal.  The <timespec> should be a\nnumber, defaulting to hours, optionally suffixed by one character:  `d'  for  days,  `h'  for\nhours,  `m' for minutes, or `s' for seconds.  Following the time option, one or more directo‐\nries must be given for tmpreaper to clean up.\n\nOn linux ext2/ext3/ext4 filesystems, no errors will be given  when  trying  to  remove  files\nmarked  as  immutable. A common situation for this was the ext3 .journal file. However, there\nmay of course be other files marked as such by the system administrator.\n\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "<noargs>, -h, --help",
                    "content": "Print a brief version, copyright, and usage statement on stderr, then exit with  error\nstatus 1.\n\n"
                },
                {
                    "name": "-t, --test",
                    "content": "Don't  actually remove any files, but go through the motions, checking through the di‐\nrectory, then pretend to remove the eligible files.\n\n",
                    "flag": "-t",
                    "long": "--test"
                },
                {
                    "name": "-v, --verbose",
                    "content": "Print a verbose display. Two levels of verbosity are available---use this option twice\nto get the most verbose output.  The --test option automaticly sets --verbose once.\nHigher numbers mean more output (max. is 3).\nTo force normal verbosity after --test, use \"--verbose=0\".  This will  generally  only\nshow error messages. Use \"--test --verbose=0 --showdeleted\" to give a shellscript-like\nlist of actions that would have been done (see the --showdeleted description below).\n\n",
                    "flag": "-v",
                    "long": "--verbose"
                },
                {
                    "name": "--showdeleted",
                    "content": "Show  what  files and directories are deleted. The output is in the form of shell com‐\nmands, i.e. \"rm /dir/dir2/file\" and \"rmdir /dir/dir2\".\nWhen used together with --test, this option will still cause the \"shell  commands\"  to\nbe printed, although nothing is really done. Note that this may show more than without\n--test, as problems removing the file won't be detected (e.g. immutable files).\n\n",
                    "long": "--showdeleted"
                },
                {
                    "name": "-f, --force",
                    "content": "Remove  files even if EUID doesn't have write access (akin to rm -f).  Normally, files\nowned by the current EUID, with no write bit set are not removed.\n\n",
                    "flag": "-f",
                    "long": "--force"
                },
                {
                    "name": "--delay=x",
                    "content": "Delay execution at the start for a random time, up to x seconds; if no value is speci‐\nfied, the default maximum time to delay is 256 seconds.  This is an option  useful  in\ncron scripts to make the execution of tmpreaper less predictable, thus making things a\nlittle harder for those who would attempt to use tmpreaper to thwart security.\n\n",
                    "long": "--delay",
                    "arg": "x"
                },
                {
                    "name": "-T x, --runtime=x",
                    "content": "Execution  of  tmpreaper will aborted after x seconds; this is to prevent attacks that\ncreate many, many files.  By default the timeout is set to 55 seconds.  A value  of  0\nwill  disable  this  feature,  which  is not advised as this feature prevents possible\nrace-conditions between different instances of tmpreaper.\n\n",
                    "flag": "-T",
                    "long": "--runtime",
                    "arg": "x"
                },
                {
                    "name": "-m, --mtime",
                    "content": "Base the decision of whether to remove the file on  its  mtime,  rather  than  on  its\natime.\n\n",
                    "flag": "-m",
                    "long": "--mtime"
                },
                {
                    "name": "-M, --mtime-dir",
                    "content": "Base  the decision of whether to remove the directory on its mtime, rather than on its\natime.\n\n",
                    "flag": "-M",
                    "long": "--mtime-dir"
                },
                {
                    "name": "-c, --ctime",
                    "content": "Base the decision of whether to remove the file on  its  ctime,  in  addition  to  its\natime.  Only applicable if the --mtime options is not given!\n\n",
                    "flag": "-c",
                    "long": "--ctime"
                },
                {
                    "name": "-s, --symlinks",
                    "content": "Remove symlinks too, not just regular files and directories.\n\n",
                    "flag": "-s",
                    "long": "--symlinks"
                },
                {
                    "name": "-a, --all",
                    "content": "Remove all file types, not just regular files, symlinks, and directories.\n\n\n--protect '<shellpattern>'\nProtect  the  files  that match the <shellpattern> from deletion.  This option may be\nused more than once.  It has no one letter abbreviation, you must spell out  the  full\nword \"protect\".\n\nIf you do not enclose the <shellpattern> in single quotes, the shell will perform the\nexpansion  before  tmpreaper  reads  its argument array.  The program does not support\nthat syntax, so you must use single quotes around the glob pattern.\n\ntmpreaper will chdir(2) into each of the directories you've specified for cleanup, and\ncheck for files matching the <shellpattern> there.  It then builds a  list  of  them,\nand uses that to protect them from removal.  For example:\n\ntmpreaper --test --verbose --protect \\\n'.X*-{lock,unix,unix/*}' --protect '.ICE-{unix{/*,}}' \\\n5d /tmp  # 5 day grace period\n\n",
                    "flag": "-a",
                    "long": "--all"
                }
            ]
        },
        "TIPS": {
            "content": "As  long as there are files present inside a subdirectory, it won't get removed.  You can use\na non-writable, self-owned file, perhaps named \".tmpreaper\", or, if you are su, a  file  that\nhas  the  ext2fs  immutable  attribute  set,  to  keep a subdirectory from being deleted.  Of\ncourse, you could just as easily use use the --protect option to obtain the same result.\n\nBecause the command line argument processing is implemented with GNU  getoptlong(3)[2],  you\nmay order the arguments thusly, if it pleases you:\n\ntmpreaper --test --verbose 5h \\\n--protect './tmp/{blah?,dir{/blah4,}}' ./tmp \\\n--protect '/tmp/.X*' /tmp\n\n...  Note that if you use --all or --symlinks, it will have global effect.  If you only want\nit turned on for one directory, you must use separate commands.\n\n",
            "subsections": []
        },
        "WARNINGS": {
            "content": "Please do not ever run tmpreaper on `/'!!! There are no safeguards against  this  built  into\nthe program, because that would make it difficult to use in a chrooted environment.\n\n\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "chattr(1) chdir(2) chroot(8) cron(1) getoptlong(3) ls(1) lsattr(1) rm(1) stat(1)\n\n[1]  http://seclists.org/lists/bugtraq/1996/May/0046.html or\nhttp://www.security-express.com/archives/bugtraq/19962/0054.html\n\nhttp://linuxgazette.net/18/tmp.html\n(formerly http://www.linuxgazette.com/issue18/tmp.html)\n\nhttp://linuxgazette.net/20/followup.html\n\n[2] info:(libc)Long Options\n\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Karl M. Hegbloom <karlheg@debian.org>\n\nMostly based on `tmpwatch-1.2/1.4', by:\nErik Troan <ewt@redhat.com>\n\nNow being maintained for Debian by:\nPaul Slootman <paul@debian.org>\n\n4th Berkeley Distribution                  Sat Jan  5 2019                              TMPREAPER(8)",
            "subsections": []
        }
    },
    "summary": "tmpreaper - removes files which haven't been accessed for a period of time",
    "flags": [
        {
            "flag": "-t",
            "long": "--test",
            "arg": null,
            "description": "Don't actually remove any files, but go through the motions, checking through the di‐ rectory, then pretend to remove the eligible files."
        },
        {
            "flag": "-v",
            "long": "--verbose",
            "arg": null,
            "description": "Print a verbose display. Two levels of verbosity are available---use this option twice to get the most verbose output. The --test option automaticly sets --verbose once. Higher numbers mean more output (max. is 3). To force normal verbosity after --test, use \"--verbose=0\". This will generally only show error messages. Use \"--test --verbose=0 --showdeleted\" to give a shellscript-like list of actions that would have been done (see the --showdeleted description below)."
        },
        {
            "flag": "",
            "long": "--showdeleted",
            "arg": null,
            "description": "Show what files and directories are deleted. The output is in the form of shell com‐ mands, i.e. \"rm /dir/dir2/file\" and \"rmdir /dir/dir2\". When used together with --test, this option will still cause the \"shell commands\" to be printed, although nothing is really done. Note that this may show more than without --test, as problems removing the file won't be detected (e.g. immutable files)."
        },
        {
            "flag": "-f",
            "long": "--force",
            "arg": null,
            "description": "Remove files even if EUID doesn't have write access (akin to rm -f). Normally, files owned by the current EUID, with no write bit set are not removed."
        },
        {
            "flag": "",
            "long": "--delay",
            "arg": "x",
            "description": "Delay execution at the start for a random time, up to x seconds; if no value is speci‐ fied, the default maximum time to delay is 256 seconds. This is an option useful in cron scripts to make the execution of tmpreaper less predictable, thus making things a little harder for those who would attempt to use tmpreaper to thwart security."
        },
        {
            "flag": "-T",
            "long": "--runtime",
            "arg": "x",
            "description": "Execution of tmpreaper will aborted after x seconds; this is to prevent attacks that create many, many files. By default the timeout is set to 55 seconds. A value of 0 will disable this feature, which is not advised as this feature prevents possible race-conditions between different instances of tmpreaper."
        },
        {
            "flag": "-m",
            "long": "--mtime",
            "arg": null,
            "description": "Base the decision of whether to remove the file on its mtime, rather than on its atime."
        },
        {
            "flag": "-M",
            "long": "--mtime-dir",
            "arg": null,
            "description": "Base the decision of whether to remove the directory on its mtime, rather than on its atime."
        },
        {
            "flag": "-c",
            "long": "--ctime",
            "arg": null,
            "description": "Base the decision of whether to remove the file on its ctime, in addition to its atime. Only applicable if the --mtime options is not given!"
        },
        {
            "flag": "-s",
            "long": "--symlinks",
            "arg": null,
            "description": "Remove symlinks too, not just regular files and directories."
        },
        {
            "flag": "-a",
            "long": "--all",
            "arg": null,
            "description": "Remove all file types, not just regular files, symlinks, and directories. --protect '<shellpattern>' Protect the files that match the <shellpattern> from deletion. This option may be used more than once. It has no one letter abbreviation, you must spell out the full word \"protect\". If you do not enclose the <shellpattern> in single quotes, the shell will perform the expansion before tmpreaper reads its argument array. The program does not support that syntax, so you must use single quotes around the glob pattern. tmpreaper will chdir(2) into each of the directories you've specified for cleanup, and check for files matching the <shellpattern> there. It then builds a list of them, and uses that to protect them from removal. For example: tmpreaper --test --verbose --protect \\ '.X*-{lock,unix,unix/*}' --protect '.ICE-{unix{/*,}}' \\ 5d /tmp # 5 day grace period"
        }
    ],
    "examples": [],
    "see_also": [
        {
            "name": "chattr",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/chattr/1/json"
        },
        {
            "name": "chdir",
            "section": "2",
            "url": "https://www.chedong.com/phpMan.php/man/chdir/2/json"
        },
        {
            "name": "chroot",
            "section": "8",
            "url": "https://www.chedong.com/phpMan.php/man/chroot/8/json"
        },
        {
            "name": "cron",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/cron/1/json"
        },
        {
            "name": "getoptlong",
            "section": "3",
            "url": "https://www.chedong.com/phpMan.php/man/getoptlong/3/json"
        },
        {
            "name": "ls",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/ls/1/json"
        },
        {
            "name": "lsattr",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/lsattr/1/json"
        },
        {
            "name": "rm",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/rm/1/json"
        },
        {
            "name": "stat",
            "section": "1",
            "url": "https://www.chedong.com/phpMan.php/man/stat/1/json"
        }
    ]
}