1 .\" $NetBSD: mtree.8,v 1.53 2010/01/20 14:00:48 wiz Exp $
3 .\" Copyright (c) 1989, 1990, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" Copyright (c) 2001-2004 The NetBSD Foundation, Inc.
31 .\" All rights reserved.
33 .\" This code is derived from software contributed to The NetBSD Foundation
34 .\" by Luke Mewburn of Wasabi Systems.
36 .\" Redistribution and use in source and binary forms, with or without
37 .\" modification, are permitted provided that the following conditions
39 .\" 1. Redistributions of source code must retain the above copyright
40 .\" notice, this list of conditions and the following disclaimer.
41 .\" 2. Redistributions in binary form must reproduce the above copyright
42 .\" notice, this list of conditions and the following disclaimer in the
43 .\" documentation and/or other materials provided with the distribution.
45 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
46 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
47 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
48 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
49 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
51 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
52 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
53 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
54 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
55 .\" POSSIBILITY OF SUCH DAMAGE.
57 .\" @(#)mtree.8 8.2 (Berkeley) 12/11/93
64 .Nd map a directory hierarchy
67 .Op Fl CcDdeLlMPrSUuWx
78 .Op Fl X Ar exclude-file
82 utility compares a file hierarchy against a specification,
83 creates a specification for a file hierarchy, or modifies
86 The default action, if not overridden by command line options,
87 is to compare the file hierarchy rooted in the current directory
88 against a specification read from the standard input.
89 Messages are written to the standard output for any files whose
90 characteristics do not match the specification, or which are
91 missing from either the file hierarchy or the specification.
93 The options are as follows:
94 .Bl -tag -width Xxxexcludexfilexx
96 Convert a specification into
97 a format that's easier to parse with various tools.
98 The input specification is read from standard input or
99 from the file given by
101 In the output, each file or directory is represented using a single line
102 (which might be very long).
106 is always printed as the first field;
111 can be used to control which other keywords are printed;
115 can be used to control which files are printed;
117 option can be used to sort the output.
119 Print a specification for the file hierarchy originating at
120 the current working directory (or the directory provided by
122 to the standard output.
123 The output is in a style using relative path names.
127 except that the path name is always printed as the last field instead of
130 Ignore everything except directory type files.
132 Add the comma separated tags to the
135 Non-directories with tags which are in the exclusion list are not printed with
140 Don't complain about files that are in the file hierarchy, but not in the
143 Read the specification from
145 instead of from the standard input.
147 Add the comma separated tags to the
150 Non-directories with tags which are in the inclusion list are printed with
154 If no inclusion list is provided, the default is to display all files.
156 If specified, set the schg and/or sappnd flags.
158 Add the specified (whitespace or comma separated) keywords to the current
162 is specified, add all of the other keywords.
166 keyword plus the specified (whitespace or comma separated)
167 keywords instead of the current set of keywords.
170 is specified, use all of the other keywords.
173 keyword is not desired, suppress it with
176 Follow all symbolic links in the file hierarchy.
180 permissions checks, in which more stringent permissions
181 will match less stringent ones.
182 For example, a file marked mode 0444
183 will pass a check for mode 0644.
185 checks apply only to read, write and execute permissions -- in
186 particular, if other bits like the sticky bit or suid/sgid bits are
187 set either in the specification or the file, exact checking will be
189 This option may not be set at the same time as the
195 Permit merging of specification entries with different types,
196 with the last entry take precedence.
198 If the schg and/or sappnd flags are specified, reset these flags.
199 Note that this is only possible with securelevel less than 1 (i.e.,
200 in single user mode or while the system is running in insecure
204 for information on security levels.
206 Use the user database text file
208 and group database text file
212 rather than using the results from the system's
216 (and related) library calls.
218 Don't follow symbolic links in the file hierarchy, instead consider
219 the symbolic link itself in any comparisons.
222 Use the file hierarchy rooted in
224 instead of the current directory.
226 Remove the specified (whitespace or comma separated) keywords from the current
230 is specified, remove all of the other keywords.
232 Remove any files in the file hierarchy that are not described in the
235 When reading a specification into an internal data structure,
237 Sorting will affect the order of the output produced by the
241 options, and will also affect the order in which
242 missing entries are created or reported when a directory tree is checked
243 against a specification.
245 The sort order is the same as that used by the
247 option, which is that entries within the same directory are
248 sorted in the order used by
250 except that entries for subdirectories sort after other entries.
253 option is not used, entries within the same directory are collected
254 together (separated from entries for other directories), but not sorted.
256 Display a single checksum to the standard error output that represents all
257 of the files for which the keyword
260 The checksum is seeded with the specified value.
262 Modify the modified time of existing files, the device type of devices, and
263 symbolic link targets, to match the specification.
267 except that a mismatch is not considered to be an error if it was corrected.
269 Modify the owner, group, permissions, and flags of existing files,
270 the device type of devices, and symbolic link targets,
271 to match the specification.
272 Create any missing directories, devices or symbolic links.
273 User, group, and permissions must all be specified for missing directories
277 option is given, the schg and sappnd flags will not be set, even if
281 is given, these flags will be reset.
282 Exit with a status of 0 on success,
283 2 if the file hierarchy did not match the specification, and
284 1 if any other error occurred.
286 Don't attempt to set various file attributes such as the
287 ownership, mode, flags, or time
288 when creating new directories or changing existing entries.
289 This option will be most useful when used in conjunction with
293 .It Fl X Ar exclude-file
294 The specified file contains
296 patterns matching files to be excluded from
297 the specification, one to a line.
298 If the pattern contains a
300 character, it will be matched against entire pathnames (relative to
301 the starting directory); otherwise,
302 it will be matched against basenames only.
303 Comments are permitted in
308 Don't descend below mount points in the file hierarchy.
311 Specifications are mostly composed of
314 that specify values relating to files.
315 No keywords have default values, and if a keyword has no value set, no
316 checks based on it are performed.
318 Currently supported keywords are as follows:
319 .Bl -tag -width sha384digestxx
321 The checksum of the file using the default algorithm specified by
326 The device number to use for
331 The argument must be one of the following forms:
334 .It Ar format , Ns Ar major , Ns Ar minor
339 fields, for an operating system specified with
341 See below for valid formats.
342 .It Ar format , Ns Ar major , Ns Ar unit , Ns Ar subunit
348 fields, for an operating system specified with
350 (Currently this is only supported by the
354 Opaque number (as stored on the file system).
357 The following values for
382 The file flags as a symbolic name.
385 for information on these names.
386 If no flags are to be set the string
388 may be used to override the current default.
389 Note that the schg and sappnd flags are treated specially (see the
395 Ignore any file hierarchy below this file.
397 The file group as a numeric value.
399 The file group as a symbolic name.
401 The file the symbolic link is expected to reference.
405 cryptographic message digest of the file.
410 The current file's permissions as a numeric (octal) or symbolic
413 The number of hard links the file is expected to have.
415 The file is optional; don't complain about the file if it's
416 not in the file hierarchy.
420 cryptographic message digest of the file.
427 cryptographic message digest of the file.
434 cryptographic message digest of the file.
441 cryptographic message digest of the file.
448 cryptographic message digest of the file.
453 The size, in bytes, of the file.
455 Comma delimited tags to be matched with
459 These may be specified without leading or trailing commas, but will be
460 stored internally with them.
462 The last modification time of the file.
464 The type of the file; may be set to any one of the following:
466 .Bl -tag -width Sy -compact
470 character special device
483 The file owner as a numeric value.
485 The file owner as a symbolic name.
488 The default set of keywords are
500 There are four types of lines in a specification:
504 Set global values for a keyword.
505 This consists of the string
507 followed by whitespace, followed by sets of keyword/value
508 pairs, separated by whitespace.
509 Keyword/value pairs consist of a keyword, followed by an equals sign
511 followed by a value, without whitespace characters.
512 Once a keyword has been set, its value remains unchanged until either
515 Unset global values for a keyword.
516 This consists of the string
518 followed by whitespace, followed by one or more keywords,
519 separated by whitespace.
522 is specified, unset all of the keywords.
524 A file specification, consisting of a path name, followed by whitespace,
525 followed by zero or more whitespace separated keyword/value pairs.
527 The path name may be preceded by whitespace characters.
528 The path name may contain any of the standard path name matching
538 in the hierarchy will be associated with the first pattern that
543 (in VIS_CSTYLE format) to encode path names containing
544 non-printable characters.
545 Whitespace characters are encoded as
553 characters in path names are escaped by a preceding backslash
555 to distinguish them from comments.
557 Each of the keyword/value pairs consist of a keyword, followed by an
560 followed by the keyword's value, without
561 whitespace characters.
562 These values override, without changing, the global value of the
563 corresponding keyword.
565 The first path name entry listed must be a directory named
567 as this ensures that intermixing full and relative path names will
568 work consistently and correctly.
569 Multiple entries for a directory named
571 are permitted; the settings for the last such entry override those
572 of the existing entry.
574 A path name that contains a slash
576 that is not the first character will be treated as a full path
577 (relative to the root of the tree).
578 All parent directories referenced in the path name must exist.
579 The current directory path used by relative path names will be updated
581 Multiple entries for the same full path are permitted if the types
584 is given, and then the types may differ);
585 in this case the settings for the last entry take precedence.
587 A path name that does not contain a slash will be treated as a relative path.
588 Specifying a directory will cause subsequent files to be searched
589 for in that directory hierarchy.
591 A line containing only the string
593 which causes the current directory path (used by relative paths)
597 Empty lines and lines whose first non-whitespace character is a hash
604 utility exits with a status of 0 on success, 1 if any error occurred,
605 and 2 if the file hierarchy did not match the specification.
607 .Bl -tag -width /etc/mtree -compact
609 system specification directory
612 To detect system binaries that have been
614 it is recommended that
616 be run on the file systems, and a copy of the results stored on a different
617 machine, or, at least, in encrypted form.
620 option should not be an obvious value and the final checksum should not be
621 stored on-line under any circumstances!
624 should be run against the on-line specifications and the final checksum
625 compared with the previous value.
626 While it is possible for the bad guys to change the on-line specifications
627 to conform to their modified binaries, it shouldn't be possible for them
628 to make it produce the same final checksum value.
629 If the final checksum value changes, the off-line copies of the specification
630 can be used to detect which of the binaries have actually been modified.
636 options can be used in combination to create directory hierarchies
637 for distributions and other such things.
692 options, and support for full paths appeared in