2

Is there anyway to get tree to behave such that, when it is run with the -P option, it will not output directories that don't have files matching the pattern somewhere inside of them?

As an example, take this directory structure:

${DIRECTORY}/
 runtime/
  runtime_library.so
  runtime_library.a
 my_libraries/
  drawing/
   drawing.so
  basic_functions/
   basic.a
 documents/
  manual.txt
 empty/

I'd like to get tree to output this:

${DIRECTORY}/
 my_libraries/
  basic_functions/
   basic.a
 runtime/
  runtime_library.a
2
  • 2
    My version of tree v1.7.0 (on fedora 23) has an option --prune to not show directories that have no matching files.
    – meuh
    Commented May 20, 2017 at 8:53
  • That's what I need, thanks. It's confusing that without --prune, all files are listed in blue and only matching ones in red, not very helpful.
    – WesternGun
    Commented Mar 15 at 9:57

1 Answer 1

3

I guess you only want directories matching a specific pattern, so you need the -P option, i.e.

tree -P "*.a" --prune

The above will return all directories containing files with the extension .a. The man page of tree can help you further. For instance, to ignore a pattern, you can use option -I.

The --prune option will suppress output of sections of the tree where directories don't contain files matching the pattern.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .