NAME

clean - clean your account...


SYNOPSIS

clean [options] [directory]

with options in:

[-a] [--all] [-c] [--check-only] [-d] [--default] [-e] [--delete-empty-dir] [-f[filename]] [--output[=filename]] [-g[#]] [--gentle[=#]] [-h] [--help] [-i] [--interactive] [-j] [--empty-junk-dir] [-l] [--follow-symbolic-links] [-mmodename] [--mode=modename] [-n] [--no-recursion] [-o] [--options] [-p] [--process-todo-file] [-r] [--generate-report] [-s] [--silent] [--quiet] [-u] [--unprotect] [-v] [--standard-output] [-w] [--with-warnings] [-x] [--strip-executables] [-z] [--zap-invalid-links] [-C] [--code-dump] [-D] [--debug] [-V] [--version]


OPTIONS

Note: switch clustering is allowed when using short options. But be sure to put last in a block any option that needs a parameter (-f for instance), for eveything that follows will be consdered as the parameter.

-a or --all
Deletes or compresses also optional files, i.e. files specified with the DELOPT and ZIPOPT options. It cannot be specified in the config file, it can only be given on the command line, for it is intended to be used only when required. If that bothers you, you can change your DELOPT or ZIPOPT options to DEL and ZIP ones, or create an alternate config file (see the -m option).

-c or --check-only
Check only. The files will not be deleted, compressed or stripped. You will only get the names of the files to process. It is interesting if you don't trust the program, and much more interesting when combined with the -f and -p options (see below).

-d or --default
This option sets the default options : non-interactive mode, no size report, messages printed on STDOUT, etc. To get a full list, try clean -do

-e or --delete-empty-dir
This option will make the script delete every empty directory it finds. I implemented it upon request, so it will be useful to at least one person (I hope).

-f[filename] or --output[=filename]
This option allows you to save the report to a file, rather than the standard output (default). If filename is not specified (ie only -f or --output), the report will be saved in the file $HOME/.clean-history. The result can be parsed by the -p option.

-g[#] or --gentle[=#]
Sets the nice level of the process. If no number is specified, the default nice value is 10. On the systems that do not implement the setpriority function (e.g. Solaris 2.x), it will display a warning and go on with normal priority.

-h or --help
Displays a help screen.

-i or --interactive
Interactive mode: asks wether to delete, compress, strip each file.

-j or --empty-junk-dir
Delete junk files in directories specified with the EMPTYDIR directive in the config file.

-l or --follow-symbolic-links
Follow symbolic links (for directories). By default, the program does no directory recursion into symbolic links.

-mmodename or --mode=modename
Activates another mode. This allows you to use different config files: if you specify the option -mmode, the config file will be changed to $HOME/.cleanrc-mode, and will be read. This option can only be specified on the command-line. If you put it in the OPTIONS directive of your config file, it will be silently ignored.

-n or --no-recursion
Process only the files in the current or specified directory, do not process subdirectories.

-o or --options
Displays the state of the current options, ie the options fixed in the $HOME/.cleanrc file, combined with the command line options before the -o flag. The program exits just after the display.

Note that the regexps are not displayed ``as is'', but that common regexp parts (.+, \.) are replaced by the corresponding shell metacharacters <*, .).

-p or --process-todo-file
Actually performs the actions suggested in the todo file (created with clean -cf). Here are the three lines that sum it all up:

    clean -cf            # Run clean in check-only mode
    vi ~/.clean-history  # Remove unwanted actions
    clean -pf            # Process the remaining todo file

-r or --generate-report
Gives a report about file sizes (total size, deleted files size, ...)

-s or --silent or --quiet
Directs all messages to /dev/null, so you won't be distracted by the reports. Maybe you'd better use the -f option ?

-u or --unprotect
The protected directories list will not be taken into account, so you can temporarily unprotect them to clean them.

-v or --standard-output
Prints the report and messages on the standard output (default).

-w or --with-warnings
Warns the user when a file is world-writable or empty.

-x or --strip-executables
Tests wether an executable is stripped ; if not, it will be stripped with strip(1) or the program specified with the directive STRIP_PRG.

-z or --zap-invalid-links
Deletes invalid symbolic links.

-C or --code-dump
Dumps the generated code, and stops. Merely for debugging purposes.

-D or --debug
Fixes the $debugmode to 1. Internal use only.

-V or --version
Print the version number on the standard output and exit.


DESCRIPTION

clean deletes, compresses or strips the files that match a certain regular expression, and a certain age.

It also can delete empty dirs, specified dirs, and invalid symbolic links. It can empty temporary and cache dirs, and warn about world-writable or empty files.

You can configure it through the file $HOME/.cleanrc.


Syntax of the config file

All the lines have the same structure:

   command=parameters

You can add commentaries in your config file. They must begin with a #. Everything following a # will be ignored.

Blank lines are also authorized.


Commands

DEL
tells what files are to be deleted. The parameters is a space separated line with 3 elements: a perl-styled regexp that the filename must match, how old it must be, and a comment. The last two parameters are optional. For example,

    DEL=.+~     -1      # backup files

will erase all backup files. If the age is not relevant, put -1 or nothing. No test will then be made on the age of the file.

DELOPT
tells what files are to be optionnaly deleted, ie only when the -a flag is set. The parameters are the same as for the DEL command. For instance,

    DELOPT=.+\.o        # object files

will erase all object files. If the age is not relevant, put -1 or nothing. No test will then be made on the age of the file.

ZIP
tells what files are to be compressed. The parameters are the same as for the DEL command. For instance,

    ZIP=.+\.e?ps        30      # eps or ps files

will compress all postscript files older than 30 days.

ZIPOPT
tells what files are to be optionnaly compressed, ie only when the -a flag is set. The parameters are the same as for the ZIP command. For instance,

    ZIPOPT=.+\.dvi      -1      # dvi files

will compress all dvi files

DELDIR
tells what directories are to be deleted. The syntax is the same as for the files (ie a regexp and a date field):

    DELDIR=\.wastebasket        -1

will delete the .wastebasket directory.

EMPTYDIR
tells what directories are to be emptied. The argument must be an absolute pathname (and *NOT* a regexp), optionally followed by an age. A ~ in the pathname is expanded to home directory. If an age is given, files are deleted only if they are older than the specified age Classical use is:

    EMPTYDIR=/usr/tmp 3
    EMPTYDIR=~/.netscape/cache

This option is activated only when the -j (junk directories) options is set.

OPTIONS
allows you to set default options. Note that the -d switch sets the builtin default options, not the ones set in the config file. For instance,

    OPTIONS=-d -x -r

will set the default options, then the -x option (strip executable files), and then the -r option (report).

These options can be overriden by the command line options. All the options (these set in the config file, and the command line ones) are read from left to right. So, if you specify

    OPTIONS=-f -v

where -f means send output to the file $HOME/.clean-history, and -v means send output to STDOUT, only the last one (STDOUT) will be taken into account.

FILE_PRG
allows you to specify the program that determines wether a file is stripped or not. It must return one line with the words 'not stripped', when the file is not stripped. Its behaviour can be broken on linux systems with a broken /etc/magic file, check before using it.

The default value is /usr/bin/file.

ZIP_PRG
allows you to specify the compression program. It must return 0 upon success. The default value is /bin/gzip -9 -q

STRIP_PRG
allows you to specify the program that strips the non-stripped files. It must return 0 upon success. The default value is /usr/bin/strip.

STRIP_AGE
allows you to specify that the files newer than the given value (in days) should not be stripped.

PROTECT
allows you to protect directories. For example, when you're developping, you don't want the object files to be deleted. You can then protect the directory, and all its subdirectories. The parameter must be an absolute path. For example,

    PROTECT=~/c

will protect the directory $HOME/c. The script won't event try to enter it. The ~ is expanded to your home directory.

HISTORY_FILE
allows you to specify the file where messages should go to when the -f option is given. Its value can be overwritten by the value given on the command-line.

HIDE_MESSAGE
gives you the ability to hide some messages. You must give the display level and an optional regexp. The most current use is to hide some WARNING messages. Note: you cannot use a whitespace in the regexp (it is used as parameter delimiter), so use the \s class.

For example,

    HIDE_MESSAGE=WARNING is\sempty

will hide all warning messages containing the string ``is empty''. Use with caution. A badly written regexp could hide text that was not intended to be hidden.

I know that the display levels are not documented. To know them, just do a grep WARNING on the program itself.


NOTES

The config file location (default: $HOME/.cleanrc) can be set in the environment variable CLEANRC.

There is a list of unauthorized regexps at the beginning of the script. It is an attempt to improve security, as the script can be very harmful. It also checks the permissions on the config file.

To see the default options, just run clean -o.

The first time you run the program, it will ask you wether to create the config file (answer yes, it cannot hurt), display the different options, and stop. It will not do any deletions or compressions. You will have to run it again to actually delete something.

If you don't trust the program, you can run clean -c, which will only print the things to do (files to delete, files to compress, etc...) without actually doing it, so you can check that its choices are right.

See also the part about the -p option (and the example).


QUOTES

From the Jargon File (3.3.1) :

:clean: 1. adj. Used of hardware or software designs, implies `elegance in the small', that is, a design or implementation that may not hold any surprises but does things in a way that is reasonably intuitive and relatively easy to comprehend from the outside. The antonym is `grungy' or {crufty}. 2. v. To remove unneeded or undesired files in a effort to reduce clutter: ``I'm cleaning up my account.'' ``I cleaned up the garbage and now have 100 Meg free on that partition.''

And from the old System V.2 administrator's guide:

``Making files is easy under the Unix operating system. Therefore, users tend to create numerous files using large amounts of file space. It has been said that the only standard thing about all Unix systems is the message-of-the-day telling users to clean up their files.''


EXAMPLES

clean -cf; vi ~/.clean-history; clean -pf

which does a check-only run with the result in the ~/.clean-history file, lets you edit it to remove unwanted actions and then processes it.

clean -gwx

cleans the current directory with warnings on, a nice priority and trying to spot unstripped executables.


ENVIRONMENT

CLEANRC : path of the configuration file.

PATH : used to determine the absolute path to gzip, file and strip

GZIP : used by gzip


FILES

$HOME/.cleanrc

$HOME/.clean-history


SEE ALSO

perl(1), strip(1), file(1), gzip(1), du(1), quota(1)


AUTHOR

Olivier AUBERT <Olivier.Aubert@enst-bretagne.fr>

based on an idea by Olivier MORBE.


BUGS

There should be some sneaky ones lying around, just waiting for some poor user to come within its reach. Be careful...

The filesize report is not very accurate (or maybe too much). It does not round the size to the block size as du(1) does.