0

I really like tree, however would like to combine it with something like find... in particular, I would like to be able to pass to it (or a similar script) as a parameter some file to find e.g. *.c so that it only prints files that end in .c and the path that leads to them.

So if e.g. we have tree returning:

.
├── bar
│   ├── b.c
│   └── c.py
└── foo
    └── a.py

then tree -find "*".c should return

.
└── bar
    └── b.c

Is there a parameter that would allow this with tree? If not, how could this be achieved?

2
  • 3
    Use tree -P *.c, find more with man tree. Commented Aug 12, 2022 at 14:59
  • Thnx, I seem to be blind... :) was looking for name at the man page, but its -P for pattern...
    – ntg
    Commented Aug 12, 2022 at 15:07

1 Answer 1

4

For the case you describe, that can be achieved with the tree command's own pattern matching options. Ex. given

$ tree dir
dir
├── bar
│   ├── b.c
│   └── c.py
└── foo
    └── a.py

2 directories, 3 files

then

$ tree -P '*.c' --prune dir
dir
└── bar
    └── b.c

1 directory, 1 file

Note the quoting of pattern '*.c' to prevent the shell from possibly expanding it to a list of matching files in the current directory.

You must log in to answer this question.

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