purgedir - fast removal of directory contents


purgedir [-d N] [-i T] [-l MIN[-MAX]] [-n] [-r] [-v] [-amin [+-]N]] [-atime [+-]N]] [-cmin [+-]N]] [-ctime [+-]N]] [-daystart] [-dry-run] [-gid N] [-keep] [-la-interval T] [-la-range MIN[-MAX]] [-max-dir N] [-mmin [+-]N]] [-mtime [+-]N]] [-name PATTERN] [-not] [-or] [-perm [-/]MODE] [-remove-dir] [-type b|c|p|f|l|s] [-uid N] [-verbose] DIR...

purgedir [-V] [-help] [-version]


Purgedir recursively removes all files and subdirectories from the supplied directories. The program is optimized for quick removal of a very large number of files on ext3 and ext4 filesystems. However, it performs better than the standard rm on other filesystems as well, in particular on ZFS and BtrFS.

For each directory argument (DIR), the program will recursively remove all files and directories in it, but will retain the directory itself (unless given the -r option, see below).

Symbolic links occuring within directories are removed, but not followed. Symbolic links as arguments are not accepted, even if they point to a directory.

Additional options are provided to ensure that the load average of the server remains within the given limits. A set of find-like predicate is provided to select the files to be removed.


Command line syntax is similar to that of find(1). All options begin with a single dash. Single-character options cannot be clustered (i.e., use -n -v, instead of -nv). Options and non-option arguments can be interspersed, that is, both

purgedir -v dir


purgedir dir -v

mean the same.

General-purpose options
, -max-dir N

Limit number of simultaneously open directories to N (default: 16).

-n, -dry-run

Dry run mode: do nothing, but print what would have been done instead.

-r, -remove-dir

Remove the top-level directories after purging them (similar to rm -r).


Keep directory hierarchy: don’t remove subdirectories even if empty.

-v, -verbose

Increase verbosity.

Load Average Control
Load average control is an optional feature which allows you to avoid peaks in the system LA during purging. It is enabled when given the -la-range option:
, -la-range MIN[-MAX]

Throttle if LA reaches MAX and resume when it falls below MIN. Both MIN and MAX can be integer or floating-point numbers.

-i, -la-interval T

Check load average each T seconds (floating point number). Default is 5.000.

Predicates allow you to select files for removal. They are a subset of find(1) predicates.

Select only files matching glob(7) PATTERN.

-type b|c|p|f|l|s

Match files of this type: b for block device, c for character device, p for FIFO, f for regular file, l (ell) for symlink, and s for socket.

Notice, that since predicates are applied only to non-directory files, the d type is deliberately not implemented.

-perm [-/]MODE

Files with matching MODE (octal). The leading - requires that all of the permission bits be set, and / requires that any of them be set. If neither is given, file mode is matched exactly.

-uid UID

Files owned by this UID number.

-gid GID

Files owned by this GID number.

The following predicates select files based on their time. If the argument starts with +, files older than the specified amount of time ago are selected. If it starts with -, files newer than that amount of time are selected.

Select files by atime in minutes.

-atime [+-]N

Select files by atime in days.

-cmin [+-]N

Select files by ctime in minutes.

-atime [+-]N

Select files by ctime in days.

-mmin [+-]N

Select files by ctime in minutes.

-mtime [+-]N

Select files by mtime in days.

By default times are measured from 24 hours ago. This is altered by the following option:

Measure times from the beginning of today rather than from 24 hours ago.

By default, multiple predicates are joined using boolean AND. The following predicates modify that:


Negate the effect of the next predicate.


Join the two adjacent predicates by logical OR.

Use parentheses to change predicate precedence. Be sure to quote them, to prevent them from being expanded by the shell. E.g.:

purgedir dir \( -perm /111 -name ’0?’ \) -or \( -perm 755 -name ’1?’ \)

Informative options
When one of these options is given, the program prints the requested piece of information and exits with status 0.


Display a short help summary.

-V, -version

Display program version and licensing information.



Successful termination.


A fatal error occurred.


Some files were not removed.


Command line usage error.




Sergey Poznyakoff


Report bugs to <gray@gnu.org>.


Copyright © 2024 Sergey Poznyakoff
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.

Manpage server at man.gnu.org.ua.

Powered by mansrv 1.1