1FASTRM(1)                 InterNetNews Documentation                 FASTRM(1)
2
3
4

NAME

6       fastrm - Quickly remove a list of files
7

SYNOPSIS

9       fastrm [-de] [-u-uN] [-s-sM] [-c-cI] base-directory
10

DESCRIPTION

12       fastrm reads a list of either file names or storage API tokens, one per
13       line, from its standard input and removes them.  Storage API tokens are
14       removed via the SMcancel() interface.  fastrm does not delete files
15       safely or with an eye to security, but rather cuts every corner it can
16       to delete files as fast as it can.  It should therefore never be run on
17       publically writable directories, or in any other environment where a
18       hostile party may control the directory structure in which it is work‐
19       ing.
20
21       If a file name is not an absolute path name, it is considered to be
22       relative to base-directory as given on the command line.  The base-
23       directory parameter must be a simple absolute pathname (it must not
24       contain multiple consecutive slashes or references to the special
25       directories "." or "..").
26
27       fastrm is designed to be faster than the typical "⎪ xargs rm" pipeline
28       when given a sorted list of file names as input.  For example, fastrm
29       will usually chdir(2) into a directory before removing files from it,
30       meaning that if its input is sorted, most names passed to unlink(2)
31       will be simple names.  This can substantially reduce the operating sys‐
32       tem overhead from directory lookups.
33
34       fastrm assumes that its input is valid and that it is safe to call
35       unlink(2) on every file name it is given.  As a safety measure, how‐
36       ever, fastrm when running as root will check with stat(2) that a file
37       name doesn't specify a directory before removing it.  (In some operat‐
38       ing systems, root is allowed to unlink directories, even directories
39       which aren't empty, which can cause file system corruption.)
40
41       The input to fastrm should always be sorted -- or even better be in the
42       order file names are output by find(1) -- if speed is an issue and the
43       input isn't solely storage API tokens.  (It deals fine with unsorted
44       input, but is unlikely to be any faster in that case than a simple
45       "xargs rm" command.)  Sorting may even slightly speed up the removal of
46       storage API tokens due to caching effects, since sorting will tend to
47       keep all of the tokens from a particular storage method together.
48
49       Various additional optimizations for removing files can be turned on
50       and/or tuned with options (see below).  Which options will be most
51       effective depends heavily on the underlying structure of the file sys‐
52       tem, the way in which directories are stored and searched, and similar,
53       often underdocumented, operating system implementation details.  The
54       more sophisticated the underlying operating system and file system, the
55       more likely that it will already perform the equivalent of these opti‐
56       mizations internally.
57

OPTIONS

59       -d  Don't remove any files.  Instead, print a list of the files that
60           would be removed to standard output.  Each line contains either the
61           current directory of fastrm at the time it would do the unlink and
62           the relative path name it would pass to unlink(2) as two fields
63           separated by whitespace and a "/", the absolute path name (as a
64           single field) that would be passed to unlink(2), or the string
65           "Token" and the storage API token that would be removed.
66
67       -e  Treat an empty input file as an error.  This is most useful when
68           fastrm is last in a pipeline after a preceding sort(1) command,
69           ensuring that fastrm will fail if the sort fails.
70
71       -cI Controls when fastrm calls chdir(2).  If the number of files to be
72           unlinked from a given directory is at least I, then fastrm will
73           change to that directory before unlinking those files.  Otherwise,
74           it will use either the absolute path names or a path name relative
75           to the current directory (whichever is likely more efficient).  The
76           I parameter is optional; if just -c is given, -c1 is assumed, which
77           will cause fastrm to always chdir before calling unlink(2).  The
78           default is -c3.  Use -c0 to prevent fastrm from ever using
79           chdir(2).
80
81       -sM When -s is given and the number of files to remove in a directory
82           is greater than M, rather than remove files in the order given,
83           fastrm will open the directory and read it, unlinking files in the
84           order that they appear in the directory.  On systems with a per-
85           process directory cache or that use a linear search to find files
86           in a directory, this should make directory lookups faster.  The M
87           parameter is optional; if just -s is given, -s5 is assumed.
88
89           When this option is in effect, fastrm won't attempt to remove files
90           that it doesn't see in the directory, possibly significantly speed‐
91           ing it up if most of the files to be removed have already been
92           deleted.  However, using this option requires fastrm to do more
93           internal work and it also assumes that the order of directory list‐
94           ings is stable in the presence of calls to unlink(2) between calls
95           to readdir(3).  This may be a dangerous assumption with some
96           sophisticated file systems (and in general this option is only use‐
97           ful with file systems that use unindexed linear searches to find
98           files in directories or when most of the files to be removed have
99           already been deleted).
100
101           This optimization is off by default.
102
103       -uN Specifying this option promises that there are no symbolic links in
104           the directory tree from which files are being removed.  This allows
105           fastrm to make an additional optimization to its calls to chdir(2),
106           constructing a relative path using "../.." and the like to pass to
107           chdir(2) rather than always using absolute paths.  Since this
108           reduces the number of directory lookups needed with deeply nested
109           directory structures (such as that typically created by traditional
110           news spool storage), it can be a significant optimization, but it
111           breaks horribly in the presence of symbolic links to directories.
112
113           When -u is given, fastrm will use at most N levels of ".."  seg‐
114           ments to construct paths.  N is optional; if just -u is given, -u1
115           is assumed.
116
117           This optimization is off by default.
118
119       fastrm also accepts -a and -r options, which do nothing at all except
120       allow you to say "fastrm -usa", "fastrm -ussr", or "fastrm -user".
121       These happen to often be convenient sets of options to use.
122

EXIT STATUS

124       fastrm exits with a status of zero if there were no problems, and an
125       exit status of 1 if something went wrong.  Attempting to remove a file
126       that does not exist is not considered a problem.
127

EXAMPLES

129       fastrm is typically invoked by INN via expirerm(8) using a command
130       like:
131
132           fastrm -e /usr/local/news/spool/articles < expire.list
133
134       To enable all optimizations and see the affect on the order of removal
135       caused by -s, use:
136
137           fastrm -d -s -e -u ~news/spool/articles < expire.list
138
139       If your file system has indexed directory lookups, but you have a
140       deeply nested directory structure, you may want to use a set of flags
141       like:
142
143           fastrm -e -u3 ~news/spool/articles < expire.list
144
145       to strongly prefer relative paths but not to use readdir(2) to order
146       the calls to unlink(2).
147
148       You may want to edit expirerm(8) to change the flags passed to fastrm.
149

WARNINGS

151       fastrm cuts corners and does not worry about security, so it does not
152       use chdir(2) safely and could be tricked into removing files other than
153       those that were intended if run on a specially constructed file tree or
154       a file tree that is being modified while it is running.  It should
155       therefore never be used with world-writable directories or any other
156       directory that might be controlled or modified by an attacker.
157

NOTES

159       fastrm defers opening the storage subsystem or attempting to parse any
160       INN configuration files until it encounters a token in the list of
161       files to remove.  It's therefore possible to use fastrm outside of INN
162       as a general fast file removal program.
163

HISTORY

165       fastrm was originally written by kre@munnari.oz.au.  This manual page
166       rewritten in POD by Russ Allbery <rra@stanford.edu> for InterNetNews.
167
168       $Id: fastrm.1 7429 2005-12-11 20:42:43Z eagle $
169

SEE ALSO

171       expirerm(8)
172
173
174
175INN 2.4.3                         2005-10-08                         FASTRM(1)
Impressum