mtree help

I'm trying to use mtree() to get a full subdirectory list but cannot find the options to simply output just the directory name.


mtree -bcd -p /boot

prints three lines for every entry. How do I simply get a list of subdirectories without anything else?
 
The purpose of mtree is to record and restore a tree including all metadata like permissions, attributes, etc, so, fully reproducible.

What you're looking for is done e.g. by find(1): find /boot -type d.

See als the XY Problem.
The reason i thought of using mtree was because of this post:-


Code:
Another tool that can do this: mtree

It first appeared on bsd systems, there are ports for linux too. In Ubuntu it is in package 'mtree-netbsd' or 'freebsd-utils'.

# 1: cd to your source dir
cd my_source_dir

# 2: create a specfile. Place the spec outside of the sourcedir and destdir
mtree -c > /tmp/myspec.txt

# 3: cd to the destdir
cd my_dest_dir

# 4: now create only the dir structure from the specfile
# -u  is for creating only dirs, it does not follow links
mtree -f /tmp/myspec.txt -u
If you later deleted some dirs in the destdir call the command form step 4 again, dir-structure will be restored.

mtree can do a lot more. follow links, create/delete specific files/dirs, delete or not delete files that are in the destdir...

but I couldn't get it to work, hence my question...

I guess I'll try find() instead.
 
If you want to replicate a directory structure, including "everything", mtree(8) is your tool. What you're quoting here doesn't contradict that. Then you really shouldn't care about the format of the specification mtree creates. Just use exactly that specification to restore the tree.

If, on the other hand, you just want to see a list of all directories in some tree (like your initial question suggested), find(1) can tell you that easily.
 
Back
Top