SHTOOL-ROTATE.TMP(1)
β¨ SHTOOL-ROTATE.TMP β GNU shtool log file rotation β¨
okay bestie, listen up π this one is from the GNU Portable Shell Tool manual family, it's called shtool-rotate, and it's literally the girl who does log rotation for you. let's get into it π
πΈ SYNOPSIS πΈ
shtool rotate [-v|--verbose] [-t|--trace] [-f|--force] [-n|--num-files
count] [-s|--size size] [-c|--copy] [-r|--remove] [-a|--archive-dir dir]
[-z|--compress [tool:]level] [-b|--background] [-d|--delay] [-p|--pad
len] [-m|--mode mode] [-o|--owner owner] [-g|--group group]
[-M|--migrate cmd] [-P|--prolog cmd] [-E|--epilog cmd] file [file ...]
like. that's a lot of flags. but she's worth it π
π¦ DESCRIPTION π¦
this command rotates a logfile file by subsequently creating up to count (optionally compressed) archive files of it, no cap. archive files are named:
file.number[compress-suffix]
where number is the version number β 0 being the newest and count-1 the oldest. oldest queen stays in the back, periodt.
a rotation step consists of the following steps:
- remove last archive file
- shift archive file numbers
- create archive file 0 from file
- truncate/recreate file
iconic four-step routine honestly π₯
π OPTIONS π
the following command line options are available. (yes, all of them. we're doing this π«Ά)
-v,--verboseβ display some processing information. she's chatty, we love her.-t,--traceβ enable the output of the essential shell commands which are executed. it's giving transparency β¨-f,--forceβ force silent creation of archive directory if it does not exists. also skip missing intermediate logfiles in the rotation step. default is to exit with error in both cases.FIXME-n,--num-filescount β create count archive files. default is10.-s,--sizesize β only rotate if logfile exceeds size. the argument size can be specified also with the trailing units"K"(kilo),"M"(mega) or"G"(giga). the"prolog"and"epilog"are only executed if rotation actually takes place. no unnecessary drama, only real rotation π-c,--copyβ copy file to archive then truncate original. the default is to move file to archive.
unless an application reopens its logfile it will continue to write to the same file. in the default move case the application will write to the archive which it had previously opened as file. in the copy case the application will write to the original file. the drawback of the copy approach is that logfile entries are lost when they are written to file between the execution of the copy and the truncation operation. the drawback of the move approach is that the application needs to detect the move or must be triggered to reopen its log (i.e. through epilog).
so basically: pick your struggle, bestie π both have a catch, and the manpage is NOT hiding it.
-r,--removeβ removes file after rotation instead of providing a new empty file. bye girl π-a,--archive-dirdir β specify the archive directory. default is to create archives in the same directory as file is located.-z,--compress[tool:]levelβ enables compression of archive files with compression level level. by default, the toolsbzip2(1),gzip(1)andcompress(1)are searched for in$PATH, but one also can override this by prefixing the compression level with one of the three particular tool names.-b,--backgroundβ enable background compression. multitasking queen π-d,--delayβ delays the compression of archive file number0. this is useful if`-c`is not used, because an application might continue to write to archive file0through an already open file handle.-p,--padlen β enables padding with leading zeros in the number part of the filenamefile.numbercompress-suffix. the default padding len is1. this is interesting if more than 10 archive files are used, because it leads to still sorted directory listings. aesthetic AND functional πΈ-m,--modemode β the file mode applied to the created files, seechmod(1). setting mode to"-"skips this step and leaves the operating system default which is usually based onumask(1). some file modes require superuser privileges to be set. default is0755.-o,--ownerowner β the file owner name or id applied to the created files, seechown(1). this option requires superuser privileges to execute. default is to skip this step and leave the operating system default which is usually based on the executing uid or the parent setuid directory.-g,--groupgroup β the file group name or id applied to the created files, seechgrp(1). this option requires superuser privileges to execute to the fullest extend, otherwise the choice of group is limited on most operating systems. default is to skip this step and leave the operating system default which is usually based on the executing gid or the parent setgid directory.-M,--migratecmd β execute a"migration"command just before the archive file number count-1 is removed from the filesystem. the specified cmd receives the archive filename as command line argument. one last goodbye ritual π―οΈ-P,--prologcmd β execute a"prolog"command before the rotation step. useful in conjunction with-s.-E,--epilogcmd β execute a"epilog"command after the rotation step. useful in conjunction with-s.
π EXAMPLE π
# shell script
shtool rotate -n10 -s1M -zbzip2:9 -d -r /var/log/ap.access.log
shtool rotate -n5 -s128K -zbzip2:9 -d -r /var/log/ap.error.log
apachectl graceful
look at her go π apache graceful at the end is the main character moment fr fr.
π HISTORY π
the GNU shtool rotate command was originally written by Ralf S. Engelschall <rse@engelschall.com> in 2001 for GNU shtool. its development was prompted by the need to have a flexible logfile rotation facility in the OpenPKG project. a true origin story π
π SEE ALSO π
okay that's the whole thing bestie, you're officially a log rotation girlie now π¦
this was shtool 2.0.8 from 18-Jul-2008 β the source/version line and date, tucked in right here at the end like a little signature π mwah, go rotate something β¨
π¦ where this page comes from
- debian bookworm: shtool 2.0.8-10 Β· GPL-2.0-or-later
- debian trixie: shtool 2.0.8-10 Β· GPL-2.0-or-later
- ubuntu jammy: shtool 2.0.8-10 Β· GPL-2.0-or-later
- ubuntu noble: shtool 2.0.8-10 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms