mtree - map a directory hierarchy
mtree [-cdeilnqrtUux] [-f spec] [-K keywords] [-k keywords]
The utility mtree compares the file hierarchy rooted in the
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:
-c Print a specification for the file hierarchy to the
-d Ignore everything except directory type files.
-e Don't complain about files that are in the file hierarchy, but
not in the specification.
Read the specification from file spec, instead of
from the standard
-i Indents the output 4 spaces each time a directory
level is descended
when creating a specification with the -c
does not affect either the /set statements or the
each directory. It does however affect the comment
close of each directory.
Add the specified (whitespace or comma separated)
keywords to the
current set of keywords.
Use the ``type'' keyword plus the specified (whitespace or comma
separated) keywords instead of the current set of
-l Do ``loose'' permissions checks, in which more
will match less stringent ones. For example,
a file marked
mode 0444 will pass a check for mode 0644.
``Loose'' checks apply
only to read, write and execute permissions --
if other bits like the sticky bit or suid/sgid bits
are set either
in the specification or the file, exact checking will be
performed. This flag may not be set at the same
time as the -u
or -U flags.
-n Do not emit pathname comments when creating a specification.
Normally a comment is emitted before each directory
the close of that directory when using the -c option.
Use the file hierarchy rooted in path, instead of
the current directory.
-q Quiet mode. Do not complain when a ``missing'' directory cannot
be created because it already exists. This occurs
when the directory
is a symbolic link.
-r Remove any files in the file hierarchy that are not
Display a single checksum to the standard error output that represents
all of the files for which the keyword cksum
The checksum is seeded with the specified
-t If a file's timestamp is different from the specification,
``touch'' it to match the specification (and list as
-U Modify the owner, group, and permissions of existing
match the specification and create any missing directories. User,
group, and permissions must all be specified for
to be created. Exit with a status of 0 on
if any error occurred; a mismatch is not considered
an error if
it was corrected.
-u Same as the -U option except a status of 2 is returned if the
file hierarchy did not match the specification.
-x Don't descend below mount points in the file hierarchy.
Specifications are mostly composed of ``keywords'' (i.e.,
specify values relating to files). No keywords have default
if a keyword has no value set, no checks based on it are
Currently supported keywords are as follows:
cksum The checksum of the file using the default algorithm specified
by the cksum(1) utility.
flags The current file's flags (whitespace or comma
symbolic form as specified by chflags(1). The
``none'' may be used to indicate that no flags
should be set
on the file.
gid The file group as a numeric value.
gname The file group as a symbolic name.
ignore Ignore any file hierarchy below this file.
md5digest The MD5 message digest of the file.
mode The current file's permissions as a numeric (octal) or symbolic
nlink The number of hard links the file is expected to
nochange Do not change the attributes (owner, group,
mode, etc) on a
file or directory.
optional The file is optional; don't complain about the
file if it's
not in the file hierarchy.
The RIPEMD-160 message digest of the file.
sha1digest The SHA-1 message digest of the file.
uid The file owner as a numeric value.
uname The file owner as a symbolic name.
size The size, in bytes, of the file.
link The file the symbolic link is expected to reference.
time The last modification time of the file.
type The type of the file; may be set to any one of
block block special device
char character special device
file regular file
link symbolic link
The default set of keywords are gid, mode, nlink, size,
link, time, and
There are four types of lines in a specification.
The first type of line sets a global value for a keyword,
and consists of
the string ``/set'' followed by whitespace, followed by sets
pairs, separated by whitespace. Keyword/value
of a keyword, followed by an equals sign (`='), followed by
without whitespace characters. Once a keyword has been set,
remains unchanged until either reset or unset.
The second type of line unsets keywords and consists of the
``/unset'', followed by whitespace, followed by one or more
separated by whitespace.
The third type of line is a file specification and consists
of a file
name, followed by whitespace, followed by zero or more
keyword/value pairs. The file name may be preceded by
characters. The file name may contain any of the standard
matching characters (``['', ``]'', ``?'', or ``*''), in
which case files
in the hierarchy will be associated with the first pattern
Each of the keyword/value pairs consist of a keyword, followed by an
equals sign, followed by the keyword's value, without
These values override, without changing, the global
value of the
All paths are relative. Specifying a directory will cause
files to be searched for in that directory hierarchy. Which
brings us to
the last type of line in a specification: a line containing
string ``..'' causes the current directory path to ascend
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. A
status of 2 is converted to a status of 0 if the -U option
/etc/mtree system specification directory
To detect system binaries that have been ``trojan horsed'',
it is recommended
that mtree -K sha1digest be run on the file systems,
and a copy of
the results stored on a different machine, or, at least, in
form. The output file itself should be digested using the
Then, periodically, mtree and sha1(1) should be run
against the online
specifications. While it is possible for the bad guys
to change the
on-line specifications to conform to their modified binaries, it is believed
to be impractical for them to create a modified specification
which has the same SHA1 digest as the original.
The -d and -u options can be used in combination to create
for distributions and other such things; the files
/etc/mtree were used to create almost all directories in a
chgrp(1), chmod(1), cksum(1), md5(1), rmd160(1), sha1(1),
fts(3), md5(3), rmd160(3), sha1(3), chown(8)
The mtree utility appeared in 4.3BSD-Reno.
OpenBSD 3.6 December 11, 1993
[ Back ]