The tidy function is used to delete (remove permanently) unwanted files
from a system. It is useful for tidying up in /tmp
or cleaning
out core
files from users' home directories. The form of an
entry is:
tidy: class:: /directory pattern=wildcard recurse=number/inf age=days size=number/empty type=ctime/mtime/atime dirlinks=keep/tidy/delete rmdirs=true/false/all/sub links=stop/keep/traverse/tidy define=classlist elsedefine=classlist syslog=true/on/false/off inform=true/on/false/off filter=filter alias include=pattern exclude=pattern
Note that, each of the options below can be written in either upper or lower case and abbreviated by any unique abbreviation.
/directory
home
may be used instead of an explicit directory, in which case cfengine
iterates over all home directories. It is compulsory to specify a
directory.
pattern=wildcard
recurse=number/inf
inf
then cfengine opens all subdirectories and files beginning
from the specified filename. See section Recursion.
age=days
links=stop/traverse/tidy
-l
command line option) you may give this option the value
true
, or traverse
, or follow
. To specify no
recursion you set the value false
or stop
.
Note that the value set here in the cfengine program always
overrides the value set by the -l
command line option, so you
can protect certain actions from this command line option by specifying
a negative value here. If you specify no value here, the behaviour is
determined by what you specify on the command line.
The value links=tidy
has the same effect as the `-L' command
line option except that here it may be specified per item rather than
globally. Setting this value causes links which point to non-existent
files to be deleted. This feature will not work on commands with the
`home' wildcard feature. If you want to clean up old links you
should either user a files
command or the command line option
which sets the tidy feature globally.
size=number/empty
age
. The default size is zero so that any
file which gets matched by another critereon is deleted. However, if you
want to single out only totally empty files, the empty
may be used.
With this option only empty files, nevery files with anything in them,
will be deleted, if older than age
. By default, the filesizes
are in kilobytes, but kilobytes and megabytes may also be specified by
appending b,k,m to the numbers. Only the first character after the
number is significant so you may write the numbers however it might be
convenient, e.g. 14k, 14kB, 14kilobytes, the same as
for disable
.
type=ctime/mtime/atime
age
. The default is to compare access times (atime) or
the last time the file was read. A comparison by modification
time (mtime) uses the last time the contents of the file was
changed. The ctime parameter is the last time the contents, owner
or permissions of the file were changed.
dirlinks=keep/tidy/delete
rmdirs
option. You need both to make links
to directories disappear.
rmdirs=true/false/all/sub
dirlinks
, so that even
links which point to empty directories will be removed.
If this is set to `sub' then the topmost directory will not
be removed, only sub-directories.
define=classlist
Take a look at the following example:
tidy: AllHomeServers:: home pattern=core R=inf age=0 home pattern=*~ R=inf age=7 home pattern=#* R=inf age=30 any:: /tmp/ pat=* R=inf age=1 / pat=core R=2 age=0 /etc pat=hosts.equiv r=0 age=0
In the first example, all hosts in the group AllHomeServers
iterate a search over all user home directories looking for `core' files
(older than zero days) and emacs
backup files `*~',
`#*' older than seven days.
The default values for these options are the empty string for the wildcard pattern, zero for the recursion and a specification of the age is compulsory.
When cfengine tidies users' home directories, it keeps a log of all the
files it deletes each time it is run. This means that, in case of
accidents, the user can see that the file has been deleted and restore
it from backup. The log file is called .cfengine.rm
and it is
placed in the home directory of each user. The file is owned by root,
but is readable to the user concerned.
Go to the first, previous, next, last section, table of contents.