{
    "mode": "man",
    "parameter": "ROTATELOGS",
    "section": "8",
    "url": "https://www.chedong.com/phpMan.php/man/ROTATELOGS/8/json",
    "generated": "2026-10-06T11:37:24Z",
    "synopsis": "rotatelogs  [ -l ] [ -L linkname ] [ -p program ] [ -f ] [ -D ] [ -t ] [ -v ] [ -e ] [ -c ] [\n-n number-of-files ] logfile rotationtime|filesize(B|K|M|G) [ offset ]",
    "sections": {
        "NAME": {
            "content": "rotatelogs - Piped logging program to rotate Apache logs\n\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "rotatelogs  [ -l ] [ -L linkname ] [ -p program ] [ -f ] [ -D ] [ -t ] [ -v ] [ -e ] [ -c ] [\n-n number-of-files ] logfile rotationtime|filesize(B|K|M|G) [ offset ]\n\n\n",
            "subsections": []
        },
        "SUMMARY": {
            "content": "rotatelogs is a simple program for use in conjunction with Apache's piped logfile feature. It\nsupports rotation based on a time interval or maximum size of the log.\n\n\n",
            "subsections": []
        },
        "OPTIONS": {
            "content": "",
            "subsections": [
                {
                    "name": "-l",
                    "content": "time(3) formatting with size-based rotation.\n",
                    "flag": "-l"
                },
                {
                    "name": "-L _",
                    "content": "",
                    "flag": "-L"
                },
                {
                    "name": "-p _",
                    "content": "If given, rotatelogs will execute the specified program every time a new log  file  is\nopened.  The  filename of the newly opened file is passed as the first argument to the\nprogram. If executing after a rotation, the old log file is passed as the second argu‐\nment. rotatelogs does not wait for the specified program to terminate before  continu‐\ning  to  operate, and will not log any error code returned on termination. The spawned\nprogram uses the same stdin, stdout, and stderr as rotatelogs itself, and also  inher‐\nits the environment.\n",
                    "flag": "-p"
                },
                {
                    "name": "-f",
                    "content": "waiting for the first logfile entry to be read (for non-busy sites,  there  may  be  a\nsubstantial  delay  between  when  the server is started and when the first request is\nhandled, meaning that the associated logfile does not \"exist\" until then, which causes\nproblems from some automated logging tools)\n",
                    "flag": "-f"
                },
                {
                    "name": "-D",
                    "content": "do not already exist. This allows strftime(3) formatting to be used in  the  path  and\nnot just the filename.\n",
                    "flag": "-D"
                },
                {
                    "name": "-t",
                    "content": "processed in real time by a command like tail, and there is no need for archived data.\nNo suffix will be added to the filename, however format strings containing '%' charac‐\nters will be respected.\n",
                    "flag": "-t"
                },
                {
                    "name": "-T",
                    "content": "the  format  string  contains  something that will loop around, such as the day of the\nmonth. Available in 2.4.56 and later.\n",
                    "flag": "-T"
                },
                {
                    "name": "-v",
                    "content": "parsing, and all file open and close actions.\n",
                    "flag": "-v"
                },
                {
                    "name": "-e",
                    "content": "time by a further tool in the chain.\n",
                    "flag": "-e"
                },
                {
                    "name": "-c",
                    "content": "",
                    "flag": "-c"
                },
                {
                    "name": "-n _",
                    "content": "Use a circular list of filenames without timestamps. This option overwrites log  files\nat  startup  and  during  rotation. With -n 3, the series of log files opened would be\n\"logfile\", \"logfile.1\", \"logfile.2\", then overwriting  \"logfile\".  When  this  program\nfirst  opens  \"logfile\", the file will only be truncated if -t is also provided. Every\nsubsequent rotation will always begin with truncation of the  target  file.  For  size\nbased  rotation  without -t and existing log files in place, this option may result in\nunintuitive behavior such as initial log entries being sent to  \"logfile.1\",  and  en‐\ntries  in  \"logfile.1\" not being preserved even if later \"logfile.n\" have not yet been\nused. Available in 2.4.5 and later.\n\nlogfile\n\nrotationtime\nThe time between log file rotations in seconds. The rotation occurs at  the  beginning\nof  this interval. For example, if the rotation time is 3600, the log file will be ro‐\ntated at the beginning of every hour; if the rotation time is 86400, the log file will\nbe rotated every night at midnight. (If no data is logged during an interval, no  file\nwill be created.)\n\nfilesize(B|K|M|G)\nThe maximum file size in followed by exactly one of the letters B (Bytes), K (KBytes),\nM (MBytes) or G (GBytes). .PP When time and size are specified, the size must be given\nafter the time. Rotation will occur whenever either time or size limits are reached.\n\noffset The  number  of  minutes offset from UTC. If omitted, zero is assumed and UTC is used.\nFor example, to use local time in the zone UTC -5 hours, specify a value of  -300  for\nthis argument. In most cases, -l should be used instead of specifying an offset.\n\n",
                    "flag": "-n"
                }
            ]
        },
        "EXAMPLES": {
            "content": "CustomLog \"|bin/rotatelogs /var/log/logfile 86400\" common\n\n\n\nThis  creates  the files /var/log/logfile.nnnn where nnnn is the system time at which the log\nnominally starts (this time will always be a multiple of the rotation time, so you  can  syn‐\nchronize  cron scripts with it). At the end of each rotation time (here after 24 hours) a new\nlog is started.\n\n\nCustomLog \"|bin/rotatelogs -l /var/log/logfile.%Y.%m.%d 86400\" common\n\n\n\nThis creates the files /var/log/logfile.yyyy.mm.dd where yyyy is the year, mm is  the  month,\nand  dd is the day of the month. Logging will switch to a new file every day at midnight, lo‐\ncal time.\n\n\nCustomLog \"|bin/rotatelogs /var/log/logfile 5M\" common\n\n\n\nThis configuration will rotate the logfile whenever it reaches a size of 5 megabytes.\n\n\nErrorLog \"|bin/rotatelogs /var/log/errorlog.%Y-%m-%d-%H%M%S 5M\"\n\n\n\nThis configuration will rotate the error logfile whenever it reaches a size of  5  megabytes,\nand the suffix to the logfile name will be created of the form errorlog.YYYY-mm-dd-HHMMSS.\n\n\nCustomLog \"|bin/rotatelogs -t /var/log/logfile 86400\" common\n\n\n\nThis  creates  the  file /var/log/logfile, truncating the file at startup and then truncating\nthe file once per day. It is expected in this scenario that a separate process (such as tail)\nwould process the file in real time.\n\n\nCustomLog \"|bin/rotatelogs -T /var/log/logfile.%d 86400\" common\n\n\n\nIf the server is started  (or  restarted)  on  the  first  of  the  month,  this  appends  to\n/var/log/logfile.01.  When  a  log entry is written on the second of the month, /var/log/log‐\nfile.02 is truncated and new entries will be added to the top. This  example  keeps  approxi‐\nmately 1 months worth of logs without external maintenance.\n\n",
            "subsections": []
        },
        "PORTABILITY": {
            "content": "The  following logfile format string substitutions should be supported by all strftime(3) im‐\nplementations, see the strftime(3) man page for library-specific extensions.\n\n\n• %A - full weekday name (localized)\n\n\n• %a - 3-character weekday name (localized)\n\n\n• %B - full month name (localized)\n\n\n• %b - 3-character month name (localized)\n\n\n• %c - date and time (localized)\n\n\n• %d - 2-digit day of month\n\n\n• %H - 2-digit hour (24 hour clock)\n\n\n• %I - 2-digit hour (12 hour clock)\n\n\n• %j - 3-digit day of year\n\n\n• %M - 2-digit minute\n\n\n• %m - 2-digit month\n\n\n• %p - am/pm of 12 hour clock (localized)\n\n\n• %S - 2-digit second\n\n\n• %U - 2-digit week of year (Sunday first day of week)\n\n\n• %W - 2-digit week of year (Monday first day of week)\n\n\n• %w - 1-digit weekday (Sunday first day of week)\n\n\n• %X - time (localized)\n\n\n• %x - date (localized)\n\n\n• %Y - 4-digit year\n\n\n• %y - 2-digit year\n\n\n• %Z - time zone name\n\n\n• %% - literal `%'\n\n\nApache HTTP Server                           2023-03-05                                ROTATELOGS(8)",
            "subsections": []
        }
    },
    "summary": "rotatelogs - Piped logging program to rotate Apache logs",
    "flags": [
        {
            "flag": "-l",
            "long": null,
            "arg": null,
            "description": "time(3) formatting with size-based rotation."
        },
        {
            "flag": "-L",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-p",
            "long": null,
            "arg": null,
            "description": "If given, rotatelogs will execute the specified program every time a new log file is opened. The filename of the newly opened file is passed as the first argument to the program. If executing after a rotation, the old log file is passed as the second argu‐ ment. rotatelogs does not wait for the specified program to terminate before continu‐ ing to operate, and will not log any error code returned on termination. The spawned program uses the same stdin, stdout, and stderr as rotatelogs itself, and also inher‐ its the environment."
        },
        {
            "flag": "-f",
            "long": null,
            "arg": null,
            "description": "waiting for the first logfile entry to be read (for non-busy sites, there may be a substantial delay between when the server is started and when the first request is handled, meaning that the associated logfile does not \"exist\" until then, which causes problems from some automated logging tools)"
        },
        {
            "flag": "-D",
            "long": null,
            "arg": null,
            "description": "do not already exist. This allows strftime(3) formatting to be used in the path and not just the filename."
        },
        {
            "flag": "-t",
            "long": null,
            "arg": null,
            "description": "processed in real time by a command like tail, and there is no need for archived data. No suffix will be added to the filename, however format strings containing '%' charac‐ ters will be respected."
        },
        {
            "flag": "-T",
            "long": null,
            "arg": null,
            "description": "the format string contains something that will loop around, such as the day of the month. Available in 2.4.56 and later."
        },
        {
            "flag": "-v",
            "long": null,
            "arg": null,
            "description": "parsing, and all file open and close actions."
        },
        {
            "flag": "-e",
            "long": null,
            "arg": null,
            "description": "time by a further tool in the chain."
        },
        {
            "flag": "-c",
            "long": null,
            "arg": null,
            "description": ""
        },
        {
            "flag": "-n",
            "long": null,
            "arg": null,
            "description": "Use a circular list of filenames without timestamps. This option overwrites log files at startup and during rotation. With -n 3, the series of log files opened would be \"logfile\", \"logfile.1\", \"logfile.2\", then overwriting \"logfile\". When this program first opens \"logfile\", the file will only be truncated if -t is also provided. Every subsequent rotation will always begin with truncation of the target file. For size based rotation without -t and existing log files in place, this option may result in unintuitive behavior such as initial log entries being sent to \"logfile.1\", and en‐ tries in \"logfile.1\" not being preserved even if later \"logfile.n\" have not yet been used. Available in 2.4.5 and later. logfile rotationtime The time between log file rotations in seconds. The rotation occurs at the beginning of this interval. For example, if the rotation time is 3600, the log file will be ro‐ tated at the beginning of every hour; if the rotation time is 86400, the log file will be rotated every night at midnight. (If no data is logged during an interval, no file will be created.) filesize(B|K|M|G) The maximum file size in followed by exactly one of the letters B (Bytes), K (KBytes), M (MBytes) or G (GBytes). .PP When time and size are specified, the size must be given after the time. Rotation will occur whenever either time or size limits are reached. offset The number of minutes offset from UTC. If omitted, zero is assumed and UTC is used. For example, to use local time in the zone UTC -5 hours, specify a value of -300 for this argument. In most cases, -l should be used instead of specifying an offset."
        }
    ],
    "examples": [
        "CustomLog \"|bin/rotatelogs /var/log/logfile 86400\" common",
        "This  creates  the files /var/log/logfile.nnnn where nnnn is the system time at which the log",
        "nominally starts (this time will always be a multiple of the rotation time, so you  can  syn‐",
        "chronize  cron scripts with it). At the end of each rotation time (here after 24 hours) a new",
        "log is started.",
        "CustomLog \"|bin/rotatelogs -l /var/log/logfile.%Y.%m.%d 86400\" common",
        "This creates the files /var/log/logfile.yyyy.mm.dd where yyyy is the year, mm is  the  month,",
        "and  dd is the day of the month. Logging will switch to a new file every day at midnight, lo‐",
        "cal time.",
        "CustomLog \"|bin/rotatelogs /var/log/logfile 5M\" common",
        "This configuration will rotate the logfile whenever it reaches a size of 5 megabytes.",
        "ErrorLog \"|bin/rotatelogs /var/log/errorlog.%Y-%m-%d-%H%M%S 5M\"",
        "This configuration will rotate the error logfile whenever it reaches a size of  5  megabytes,",
        "and the suffix to the logfile name will be created of the form errorlog.YYYY-mm-dd-HHMMSS.",
        "CustomLog \"|bin/rotatelogs -t /var/log/logfile 86400\" common",
        "This  creates  the  file /var/log/logfile, truncating the file at startup and then truncating",
        "the file once per day. It is expected in this scenario that a separate process (such as tail)",
        "would process the file in real time.",
        "CustomLog \"|bin/rotatelogs -T /var/log/logfile.%d 86400\" common",
        "If the server is started  (or  restarted)  on  the  first  of  the  month,  this  appends  to",
        "/var/log/logfile.01.  When  a  log entry is written on the second of the month, /var/log/log‐",
        "file.02 is truncated and new entries will be added to the top. This  example  keeps  approxi‐",
        "mately 1 months worth of logs without external maintenance."
    ],
    "see_also": []
}