Hi all, I use centos7 and don't want to use tmpwatch as well as crond. I have a question to use `systemd-tmpfiles-clean.service` with my custom configured file in `tmpfiles.d` to delete outdated files periodically in some log dir. I have a `tmpfiles.d` configured file in `/etc/tmpfiles.d` named `my_log.conf` in following contents. ``` #Type Path Mode UID GID Age Arg r /chenqiang 0775 root root 10s r /chenqiang/test_10s r /chenqiang/test_20s ``` If I run `systemd-tmpfiles --remove` with above configure, all files and dir will be deleted if I set 'r' type for the files and dir. but, I want to only delete some outdated files in the dir. and I use `systemd-tmpfiles --clean` with following configure. ``` #Type Path Mode UID GID Age Arg d /chenqiang 0775 root root 10s f /chenqiang/test_10s 0660 root root 10s f /chenqiang/test_20s 0660 root root 20s ``` It can delete dir if the age > 10s, but can't delete the files in it. So, would some one help me if I want to delete the outdated files ? -- Best Regards, Chen, Qiang
Would some one help me for this question? thanks very much. On 2016?05?25? 14:18, Qiang Chen wrote:> Hi all, > > I use centos7 and don't want to use tmpwatch as well as crond. > > I have a question to use `systemd-tmpfiles-clean.service` with my > custom configured file in `tmpfiles.d` to delete outdated files > periodically in some log dir. > > I have a `tmpfiles.d` configured file in `/etc/tmpfiles.d` named > `my_log.conf` in following contents. > > ``` > #Type Path Mode UID GID Age Arg > r /chenqiang 0775 root root 10s > r /chenqiang/test_10s > r /chenqiang/test_20s > ``` > > If I run `systemd-tmpfiles --remove` with above configure, all files > and dir will be deleted if I set 'r' type for the files and dir. > but, I want to only delete some outdated files in the dir. and I use > `systemd-tmpfiles --clean` with following configure. > > ``` > #Type Path Mode UID GID Age Arg > d /chenqiang 0775 root root 10s > f /chenqiang/test_10s 0660 root root 10s > f /chenqiang/test_20s 0660 root root 20s > ``` > > It can delete dir if the age > 10s, but can't delete the files in it. > > So, would some one help me if I want to delete the outdated files ? >-- Best Regards, Chen, Qiang
On Thu, May 26, 2016 at 03:03:25PM +0800, Qiang Chen wrote:> Would some one help me for this question? thanks very much.I would suggest reading the tmpfiles.d man page. Use 'd' for the directory, and 'r' for the files you want to remove, including the age. Something like 'r /path/* - - - 10s'. -- Jonathan Billings <billings at negate.org>
On 05/24/2016 11:18 PM, Qiang Chen wrote:> #Type Path Mode UID GID Age Arg > d /chenqiang 0775 root root 10s > f /chenqiang/test_10s 0660 root root 10s > f /chenqiang/test_20s 0660 root root 20s > ``` > > It can delete dir if the age > 10s, but can't delete the files in it.The man page for tmpfiles.d says, of the age field: "The age field only applies to lines starting with d, D, and x." So, the line: d /chenqiang/test_10s 0660 root root 10s indicates that systemd-tmpfiles should create the directory /chenqiang/test_10s, owned by root/root with mode 0660, and periodically clean it of files and empty directories more than 10s old. Note that the default configuration runs systemd-tmpfiles once per day, so specifying time periods much smaller than that may not be useful.
Hi Jonathan Billings, the `age` can't apply to 'r', only would apply to 'd', 'D', 'x', 'X', etc "The age field only applies to lines starting with |d|, |D|, |v|, |q|, |Q|, |C|, |x| and |X|. If omitted or set to "|-|", no automatic clean-up is done." so, there have good idea if I only want to delete the specific files not all files in that dir? thx. On 2016?05?26? 20:54, Jonathan Billings wrote:> Boxbe <https://www.boxbe.com/overview> This message is eligible for > Automatic Cleanup! (billings at negate.org) Add cleanup rule > <https://www.boxbe.com/popup?url=https%3A%2F%2Fwww.boxbe.com%2Fcleanup%3Fkey%3DIHIC9p2jvtlLIfUym1h5cJ2bV47JU5xUSAS8hXJ6s5Y%253D%26token%3DQxrt0MFjvrbNQUv1XU7LlnUJYHBN9V92vmpaAZ9KkbO93DVkWDOu6pxjzLzV9I5d0WOIxZ6EBVn85CUoMMtN7okx0kLJV%252F7xJVwVpgcPoTZZVw8A7aTXuqXUBbLsuh%252FgEAiBRqTXvms%253D&tc_serial=25540750649&tc_rand=828171377&utm_source=stf&utm_medium=email&utm_campaign=ANNO_CLEANUP_ADD&utm_content=001> > | More info > <http://blog.boxbe.com/general/boxbe-automatic-cleanup?tc_serial=25540750649&tc_rand=828171377&utm_source=stf&utm_medium=email&utm_campaign=ANNO_CLEANUP_ADD&utm_content=001> > > > > On Thu, May 26, 2016 at 03:03:25PM +0800, Qiang Chen wrote: >> Would some one help me for this question? thanks very much. > I would suggest reading the tmpfiles.d man page. > > Use 'd' for the directory, and 'r' for the files you want to remove, > including the age. Something like 'r /path/* - - - 10s'. >-- Best Regards, Chen, Qiang