[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to use systemd to delete old files and directories on stretch?



On 2019-06-28 17:33 -0600, D. R. Evans wrote:

> My reading of the man page for tmpfiles.d suggests that if I edit the file
> /etc/tmpfiles.d/tmp.conf so that it contains the line:
>
> d /tmp 1777 root root 35d

You probably want to use 'D' rather than 'd' to ensure that /tmp is
completely emptied on reboot.

> then files in /tmp will be deleted after 35 days.

Assuming they have not been used in these 35 days.  This is how age is
defined in tmpfiles.d(5):

,----
| The age of a file system entry is determined from its last
| modification timestamp (mtime), its last access timestamp (atime),
| and (except for directories) its last status change timestamp
| (ctime). Any of these three (or two) values will prevent cleanup
| if it is more recent than the current time minus the age field.
`----

> However, that isn't happening; I see for example:
>
> drwxr-xr-x  18 n7dr n7dr        4096 May 13 07:42 Images-190513
> drwxr-xr-x  18 n7dr n7dr        4096 May 13 07:47 Images-190514
>
> in the output from "ls -alt /tmp": those directories were created more than 35
> days ago.

But they are not empty.  The link count is 18, so they both have 16
subdirectories, and who knows what files are in these subdirectories and
when they were last accessed.

> So apparently I am misunderstanding how this works. Perhaps when the man page
> says "file" it's not including directories.

No, directories are also meant.

> Anyway, whatever the reason, it's clearly not doing what I want, which
> is to remove all files and directories with names of the form
> "/tmp/<something>" that are more than 35 days old. Can someone
> enlighten me as to the correct command to do this?

If you cannot get systemd-tmpfiles-clean.service to do its job,
something like this should do the trick:

find /tmp -mindepth 1 -mtime +35 -atime +35 -delete

Cheers,
       Sven


Reply to: