1 .\" $NetBSD: mtree.8,v 1.63 2012/10/05 09:18:02 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 CcDdejLlMnPqrSUuWx
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;
118 option can be used to sort the output.
120 Print a specification for the file hierarchy originating at
121 the current working directory (or the directory provided by
123 to the standard output.
124 The output is in a style using relative path names.
128 except that the path name is always printed as the last field instead of
131 Ignore everything except directory type files.
133 Add the comma separated tags to the
136 Non-directories with tags which are in the exclusion list are not printed with
141 Don't complain about files that are in the file hierarchy, but not in the
144 Read the specification from
146 instead of from the standard input.
148 If this option is specified twice, the two specifications are compared
149 to each other rather than to the file hierarchy.
150 The specifications will be sorted like output generated using
152 The output format in this case is somewhat reminiscent of
154 having "in first spec only", "in second spec only", and "different"
155 columns, prefixed by zero, one and two TAB characters respectively.
156 Each entry in the "different" column occupies two lines, one from each
159 Add the comma separated tags to the
162 Non-directories with tags which are in the inclusion list are printed with
166 If no inclusion list is provided, the default is to display all files.
168 If specified, set the schg and/or sappnd flags.
170 Indent the output 4 spaces each time a directory level is descended when
171 creating a specification with the
174 This does not affect either the /set statements or the comment before each
176 It does however affect the comment before the close of each directory.
177 This is the equivalent of the
184 Add the specified (whitespace or comma separated) keywords to the current
188 is specified, add all of the other keywords.
192 keyword plus the specified (whitespace or comma separated)
193 keywords instead of the current set of keywords.
196 is specified, use all of the other keywords.
199 keyword is not desired, suppress it with
202 Follow all symbolic links in the file hierarchy.
206 permissions checks, in which more stringent permissions
207 will match less stringent ones.
208 For example, a file marked mode 0444
209 will pass a check for mode 0644.
211 checks apply only to read, write and execute permissions -- in
212 particular, if other bits like the sticky bit or suid/sgid bits are
213 set either in the specification or the file, exact checking will be
215 This option may not be set at the same time as the
221 Permit merging of specification entries with different types,
222 with the last entry taking precedence.
224 If the schg and/or sappnd flags are specified, reset these flags.
225 Note that this is only possible with securelevel less than 1 (i.e.,
226 in single user mode or while the system is running in insecure
230 for information on security levels.
232 Do not emit pathname comments when creating a specification.
234 a comment is emitted before each directory and before the close of that
235 directory when using the
239 Use the user database text file
241 and group database text file
245 rather than using the results from the system's
249 (and related) library calls.
251 Don't follow symbolic links in the file hierarchy, instead consider
252 the symbolic link itself in any comparisons.
255 Use the file hierarchy rooted in
257 instead of the current directory.
260 Do not complain when a
262 directory cannot be created because it already exists.
263 This occurs when the directory is a symbolic link.
265 Remove the specified (whitespace or comma separated) keywords from the current
269 is specified, remove all of the other keywords.
271 Remove any files in the file hierarchy that are not described in the
274 When reading a specification into an internal data structure,
276 Sorting will affect the order of the output produced by the
280 options, and will also affect the order in which
281 missing entries are created or reported when a directory tree is checked
282 against a specification.
284 The sort order is the same as that used by the
286 option, which is that entries within the same directory are
287 sorted in the order used by
289 except that entries for subdirectories sort after other entries.
292 option is not used, entries within the same directory are collected
293 together (separated from entries for other directories), but not sorted.
295 Display a single checksum to the standard error output that represents all
296 of the files for which the keyword
299 The checksum is seeded with the specified value.
301 Modify the modified time of existing files, the device type of devices, and
302 symbolic link targets, to match the specification.
306 except that a mismatch is not considered to be an error if it was corrected.
308 Modify the owner, group, permissions, and flags of existing files,
309 the device type of devices, and symbolic link targets,
310 to match the specification.
311 Create any missing directories, devices or symbolic links.
312 User, group, and permissions must all be specified for missing directories
316 option is given, the schg and sappnd flags will not be set, even if
320 is given, these flags will be reset.
321 Exit with a status of 0 on success,
322 2 if the file hierarchy did not match the specification, and
323 1 if any other error occurred.
325 Don't attempt to set various file attributes such as the
326 ownership, mode, flags, or time
327 when creating new directories or changing existing entries.
328 This option will be most useful when used in conjunction with
332 .It Fl X Ar exclude-file
333 The specified file contains
335 patterns matching files to be excluded from
336 the specification, one to a line.
337 If the pattern contains a
339 character, it will be matched against entire pathnames (relative to
340 the starting directory); otherwise,
341 it will be matched against basenames only.
342 Comments are permitted in
347 Don't descend below mount points in the file hierarchy.
350 Specifications are mostly composed of
353 that specify values relating to files.
354 No keywords have default values, and if a keyword has no value set, no
355 checks based on it are performed.
357 Currently supported keywords are as follows:
358 .Bl -tag -width sha384digestxx
360 The checksum of the file using the default algorithm specified by
365 The device number to use for
370 The argument must be one of the following forms:
372 .It Ar format , Ns Ar major , Ns Ar minor
377 fields, for an operating system specified with
379 See below for valid formats.
380 .It Ar format , Ns Ar major , Ns Ar unit , Ns Ar subunit
386 fields, for an operating system specified with
388 (Currently this is only supported by the
392 Opaque number (as stored on the file system).
395 The following values for
420 The file flags as a symbolic name.
423 for information on these names.
424 If no flags are to be set the string
426 may be used to override the current default.
427 Note that the schg and sappnd flags are treated specially (see the
433 Ignore any file hierarchy below this file.
435 The file group as a numeric value.
437 The file group as a symbolic name.
439 The file the symbolic link is expected to reference.
443 cryptographic message digest of the file.
448 The current file's permissions as a numeric (octal) or symbolic
451 The number of hard links the file is expected to have.
453 Make sure this file or directory exists but otherwise ignore all attributes.
455 The file is optional; don't complain about the file if it's
456 not in the file hierarchy.
457 .It Sy ripemd160digest
463 cryptographic message digest of the file.
470 cryptographic message digest of the file.
477 cryptographic message digest of the file.
484 cryptographic message digest of the file.
491 cryptographic message digest of the file.
496 The size, in bytes, of the file.
498 Comma delimited tags to be matched with
502 These may be specified without leading or trailing commas, but will be
503 stored internally with them.
505 The last modification time of the file,
506 in second and nanoseconds.
507 The value should include a period character and exactly nine digits after
510 The type of the file; may be set to any one of the following:
512 .Bl -tag -width Sy -compact
516 character special device
529 The file owner as a numeric value.
531 The file owner as a symbolic name.
534 The default set of keywords are
546 There are four types of lines in a specification:
549 Set global values for a keyword.
550 This consists of the string
552 followed by whitespace, followed by sets of keyword/value
553 pairs, separated by whitespace.
554 Keyword/value pairs consist of a keyword, followed by an equals sign
556 followed by a value, without whitespace characters.
557 Once a keyword has been set, its value remains unchanged until either
560 Unset global values for a keyword.
561 This consists of the string
563 followed by whitespace, followed by one or more keywords,
564 separated by whitespace.
567 is specified, unset all of the keywords.
569 A file specification, consisting of a path name, followed by whitespace,
570 followed by zero or more whitespace separated keyword/value pairs.
572 The path name may be preceded by whitespace characters.
573 The path name may contain any of the standard path name matching
583 in the hierarchy will be associated with the first pattern that
588 (in VIS_CSTYLE format) to encode path names containing
589 non-printable characters.
590 Whitespace characters are encoded as
598 characters in path names are escaped by a preceding backslash
600 to distinguish them from comments.
602 Each of the keyword/value pairs consist of a keyword, followed by an
605 followed by the keyword's value, without
606 whitespace characters.
607 These values override, without changing, the global value of the
608 corresponding keyword.
610 The first path name entry listed must be a directory named
612 as this ensures that intermixing full and relative path names will
613 work consistently and correctly.
614 Multiple entries for a directory named
616 are permitted; the settings for the last such entry override those
617 of the existing entry.
619 A path name that contains a slash
621 that is not the first character will be treated as a full path
622 (relative to the root of the tree).
623 All parent directories referenced in the path name must exist.
624 The current directory path used by relative path names will be updated
626 Multiple entries for the same full path are permitted if the types
629 is given, in which case the types may differ);
630 in this case the settings for the last entry take precedence.
632 A path name that does not contain a slash will be treated as a relative path.
633 Specifying a directory will cause subsequent files to be searched
634 for in that directory hierarchy.
636 A line containing only the string
638 which causes the current directory path (used by relative paths)
642 Empty lines and lines whose first non-whitespace character is a hash
649 utility exits with a status of 0 on success, 1 if any error occurred,
650 and 2 if the file hierarchy did not match the specification.
652 .Bl -tag -width /etc/mtree -compact
654 system specification directory
657 To detect system binaries that have been
659 it is recommended that
661 be run on the file systems, and a copy of the results stored on a different
662 machine, or, at least, in encrypted form.
665 option should not be an obvious value and the final checksum should not be
666 stored on-line under any circumstances!
669 should be run against the on-line specifications and the final checksum
670 compared with the previous value.
671 While it is possible for the bad guys to change the on-line specifications
672 to conform to their modified binaries, it shouldn't be possible for them
673 to make it produce the same final checksum value.
674 If the final checksum value changes, the off-line copies of the specification
675 can be used to detect which of the binaries have actually been modified.
679 option can be used in combination with
683 to create directory hierarchies for, for example, distributions.
738 options, and support for full paths appeared in