Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - rclean


rclean - selectively archives and deletes old files on a remote host


rclean [ -a <age> ] [ -c <config> ] [ -d ] [ -l ] [ -t ] [ -v ] <host_name>


rclean is a Bourne shell script which should work equally well on all versions of UNIX and Linux.


rclean Is a hardwired host specific script used to keep a remote server's file system reasonably tidy.


-a #days Sets the minimum age threshold in days before files may be deleted. This value is normally set in the configuration file . The default is 100 days. Both the configuration file and the default are trumped by the command line option.

-c <config_file> The default configuration file is /usr/local/etc/ . An alternative configuration file may be set with the -c    option on the command line.

-d sets the script to debug mode (ie. runs with the shell option -x)

-l    turns on logging using the syslog facility. This is particularly useful where statistics are being compiled for presentation to the client, see report.

Just to make life harder the logging is done by the remote host so that host's logging facility will need to be configured for remote logging as will the administration box's to allow it to receive the remote syslog messages.

-v Sets the script to verbose mode. Each significant action will be reported on standard out.



5 0 * * * su - fulford -c "/usr/local/etc/rclean -a 8 albert"

The above is an extract from a root crontab file and illustrates the typical use of the script in practice. The files to be deleted or archived are specified within the script itself but the minimum age of the files before deletion is more flexible as it is specified on the command line and in this case is 8 days.

NB. The hostname albert is being resolved locally and does not require a fully qualified domain.


The script is quite crude having been developed to address problems experienced by City Linux clients that were running out of disk space. The script does depend on very specific file names and paths. It could be made more generic by adding a configuration file.


chkdf, chkftpd, chkfw, secscan.


Clifford W Fulford, City Linux. Contact or +44 (0)709 229 5385.

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.