cleandir - remove unused files from directory


cleandir [-d days] [-n] [-m] [-v] [-s] [-i|-x regex] directory...


cleandir recursively searches each directory given on the commandline for files and subdirectories which have not been accessed for n days and deletes them. It is intended to be used on /tmp and other world-writable directories and implements a number of checks to prevent symlink or directory switching attacks. It also does not cross mount points.


-d days

Delete files which have not been accessed for the given number of days. The default is 14.


Consider only the last modification time of the file, not the last access time.


Consider only the inode change time of the file.


No-op. Don't delete any files.


Skip sockets and named pipes. Some programs (notably X11 and some databases) create sockets and named pipes in /tmp and foolishly expect them to survive. This option exists to humour them.


Verbose. Can be repeated to increase verbosity.

-i|-x regex

Include and exclude patterns. The filenames (not the complete path) of all files and directories to be removed are compared against these patterns in order. The first hit determines the action. These patterns can also be used to override the -s option and to cross mount points.


Peter J. Holzer <>. Thanks to Chris Mason for some enhancements.