| MTREE(8) | System Manager's Manual | MTREE(8) | 
mtree —
| mtree | [ -bCcDdejLlMnPqrStUuWx]
      [-i|-m]
      [-Etags]
      [-Fflavor]
      [-fspec]
      [-Itags]
      [-Kkeywords]
      [-kkeywords]
      [-Ndbdir]
      [-Oonlyfile]
      [-ppath]
      [-Rkeywords]
      [-sseed]
      [-Xexclude-file] | 
mtree utility compares a file hierarchy against a
  specification, creates a specification for a file hierarchy, or modifies a
  specification.
The default action, if not overridden by command line options, is to compare the file hierarchy rooted in the current directory against a specification read from the standard input. Messages are written to the standard output for any files whose characteristics do not match the specification, or which are missing from either the file hierarchy or the specification.
The options are as follows:
-b-C-f spec. In
      the output, each file or directory is represented using a single line
      (which might be very long). The full path name (beginning with
      “./”) is always printed as the first field;
      -K, -k, and
      -R can be used to control which other keywords are
      printed; -E and -I can be
      used to control which files are printed; and the
      -S option can be used to sort the output.-c-p
      path) to the standard output. The output is in a
      style using relative path names.-D-C, except that the path name is always
      printed as the last field instead of the first.-d-E
    tags-C and -D.-e-F
    flavormtree utility.
      The flavor can be one of mtree,
      freebsd9, or netbsd6. The default is
      mtree. The freebsd9 and
      netbsd6 flavors attempt to preserve output compatibility
      and command line option backward compatibility with
      FreeBSD 9.0 and NetBSD 6.0
      respectively.-f
    specIf this option is specified twice, the two specifications are
        compared to each other rather than to the file hierarchy. The
        specifications will be sorted like output generated using
        -c. The output format in this case is somewhat
        reminiscent of comm(1),
        having "in first spec only", "in second spec only",
        and "different" columns, prefixed by zero, one and two TAB
        characters respectively. Each entry in the "different" column
        occupies two lines, one from each specification.
-I
    tags-C and -D. If no inclusion
      list is provided, the default is to display all files.-i-j-c option. This
      does not affect either the /set statements or the comment before each
      directory. It does however affect the comment before the close of each
      directory. This is the equivalent of the -i option
      in the FreeBSD version of
      mtree.-K
    keywordsall’ is
      specified, add all of the other keywords.-k
    keywordsall’ is specified, use all of the
      other keywords. If the type keyword is not desired,
      suppress it with -R
    type.-L-l-U or
      -u option.-M-m-n-c option.-N
    dbdir-O
    onlypaths-P-p
    path-q-R
    keywordsall’ is
      specified, remove all of the other keywords.-r-S-C or -D options, and will
      also affect the order in which missing entries are created or reported
      when a directory tree is checked against a specification.
    The sort order is the same as that used by the
        -c option, which is that entries within the same
        directory are sorted in the order used by
        strcmp(3), except that
        entries for subdirectories sort after other entries. By default, if the
        -S option is not used, entries within the same
        directory are collected together (separated from entries for other
        directories), but not sorted.
-s
    seed-t-U-u except that a mismatch is not
      considered to be an error if it was corrected.-u-i option is
      given, the schg and sappnd flags will not be set, even if specified. If
      -m is given, these flags will be reset. Exit with
      a status of 0 on success, 2 if the file hierarchy did not match the
      specification, and 1 if any other error occurred.-W-U or -u.-X
    exclude-file/’
      character, it will be matched against entire pathnames (relative to the
      starting directory); otherwise, it will be matched against basenames only.
      Comments are permitted in the exclude-file
    file.-xSpecifications are mostly composed of “keywords”, i.e. strings that that specify values relating to files. No keywords have default values, and if a keyword has no value set, no checks based on it are performed.
Currently supported keywords are as follows:
The following values for format are recognized: native, 386bsd, 4bsd, bsdos, freebsd, hpux, isc, linux, netbsd, osf1, sco, solaris, sunos, svr3, svr4, and ultrix.
See mknod(8) for more details.
none’ may be used to override the
      current default. Note that the schg and sappnd flags are treated specially
      (see the -i and -m
      options).-E and
      -I. These may be specified without leading or
      trailing commas, but will be stored internally with them.The default set of keywords are flags, gid, link, mode, nlink, size, time, type, and uid.
There are four types of lines in a specification:
/set’ followed by whitespace,
      followed by sets of keyword/value pairs, separated by whitespace.
      Keyword/value pairs consist of a keyword, followed by an equals sign
      (‘=’), followed by a value, without
      whitespace characters. Once a keyword has been set, its value remains
      unchanged until either reset or unset./unset’, followed by whitespace,
      followed by one or more keywords, separated by whitespace. If
      ‘all’ is specified, unset all of the
      keywords.The path name may be preceded by whitespace characters. The
        path name may contain any of the standard path name matching characters
        (‘[’,
        ‘]’,
        ‘?’ or
        ‘*’), in which case files in the
        hierarchy will be associated with the first pattern that they match.
        mtree uses
        strsvis(3) (in
        VIS_OCTAL format) to encode path names
        containing non-printable characters. Whitespace characters are encoded
        as ‘\040’ (space),
        ‘\011’ (tab), and
        ‘\012’ (new line). When flavor
        netbsd6 is selected,
        strsvis(3) (in
        VIS_CSTYLE format) is used and whitespace
        characters are encoded as ‘\s’
        (space), ‘\t’ (tab), and
        ‘\n’ (new line).
        ‘#’ characters in path names are
        escaped by a preceding backslash
        ‘\’ to distinguish them from
        comments.
Each of the keyword/value pairs consist of a keyword, followed
        by an equals sign (‘=’), followed
        by the keyword's value, without whitespace characters. These values
        override, without changing, the global value of the corresponding
        keyword.
The first path name entry listed must be a directory named
        ‘.’, as this ensures that
        intermixing full and relative path names will work consistently and
        correctly. Multiple entries for a directory named
        ‘.’ are permitted; the settings
        for the last such entry override those of the existing entry.
A path name that contains a slash
        (‘/’) that is not the first
        character will be treated as a full path (relative to the root of the
        tree). All parent directories referenced in the path name must exist.
        The current directory path used by relative path names will be updated
        appropriately. Multiple entries for the same full path are permitted if
        the types are the same (unless -M is given, in
        which case the types may differ); in this case the settings for the last
        entry take precedence.
A path name that does not contain a slash will be treated as a relative path. Specifying a directory will cause subsequent files to be searched for in that directory hierarchy.
..’ which causes the current
      directory path (used by relative paths) to ascend one level.Empty lines and lines whose first non-whitespace character is a
    hash mark (‘#’) are ignored.
The mtree utility exits with a status of 0
    on success, 1 if any error occurred, and 2 if the file hierarchy did not
    match the specification.
mtree be run on the file systems, and
  a copy of the results stored on a different machine, or, at least, in
  encrypted form. The seed for the -s option should not
  be an obvious value and the final checksum should not be stored on-line under
  any circumstances! Then, periodically, mtree should be
  run against the on-line specifications and the final checksum compared with
  the previous value. While it is possible for the bad guys to change the
  on-line specifications to conform to their modified binaries, it shouldn't be
  possible for them to make it produce the same final checksum value. If the
  final checksum value changes, the off-line copies of the specification can be
  used to detect which of the binaries have actually been modified.
The -d option can be used in combination
    with -U or -u to create
    directory hierarchies for, for example, distributions.
-F option are
  incomplete by design. Known limitations are described below.
The freebsd9 flavor retains the default handling
    of lookup failures for the uname and
    group keywords by replacing them with appropriate
    uid and gid keywords rather than failing
    and reporting an error. The related -w flag is a
    no-op rather than causing a warning to be printed and no keyword to be
    emitted. The latter behavior is not emulated as it is potentially dangerous
    in the face of /set statements.
The netbsd6 flavor does not replicate the historical bug that reported time as seconds.nanoseconds without zero padding nanosecond values less than 100000000.
mtree utility appeared in
  4.3BSD-Reno. The optional keyword
  appeared in NetBSD 1.2. The -U
  option appeared in NetBSD 1.3. The
  flags and md5 keywords, and
  -i and -m options appeared in
  NetBSD 1.4. The device,
  rmd160, sha1, tags, and
  all keywords, -D,
  -E, -I,
  -L, -l,
  -N, -P,
  -R, -W, and
  -X options, and support for full paths appeared in
  NetBSD 1.6. The sha256,
  sha384, and sha512 keywords appeared in
  NetBSD 3.0. The -S option
  appeared in NetBSD 6.0.
| June 16, 2020 | NetBSD 10.0 |