1

I would like tree to display the hw files in the sub-directories like this:

.
├── exp
│   └── hw
├── src
│   └── hw.cpp2
└── tmp
    └── hw.cpp

$ /usr/bin/tree --noreport . displays all of the files:

.
├── exp
│   ├── hi
│   └── hw
├── src
│   ├── hi.cpp2
│   └── hw.cpp2
├── ssbuild.bash
├── sslogin.bash
└── tmp
    ├── hi.cpp
    └── hw.cpp

/usr/bin/tree --noreport -P *hw . gets hw w/o an extension:

.
├── exp
│   └── hw
├── src
└── tmp

/usr/bin/tree --noreport -P hw* . produces:

.
├── exp
├── src
└── tmp

Version info /usr/bin/tree --version:

tree v2.1.0 © 1996 - 2022 by Steve Baker, Thomas Moore, Francesc Rocher, Florian Sesser, Kyosuke Tokoro

1 Answers1

1

The tree utility has a specific option, -P, for specifying a pattern that the filenames must match to be part of the output. The type of pattern used with -P is a shell filename globbing pattern, and as such, it needs to be quoted to avoid having the shell expand it on the command line.

tree -P 'hw*' .

Since your current directory doesn't contain any name matching *hw (and since you are using a shell that does not complain about non-matching globbing patterns, like zsh would do by default, and like bash would do with its failglob shell option set), the pattern wasn't expanded when you tried to use it. However, that pattern only matches names that end in the string hw. I can however not explain why you get that output when using hw* on the command line.

Example:

$ tree .
.
├── exp
│   ├── hi
│   └── hw
├── src
│   ├── hi.cpp2
│   └── hw.cpp2
├── ssbuild.bash
├── sslogin.bash
└── tmp
    ├── hi.cpp
    └── hw.cpp

3 directories, 8 files

$ tree -P 'hw*' .
.
├── exp
│   └── hw
├── src
│   └── hw.cpp2
└── tmp
    └── hw.cpp

3 directories, 3 files
Kusalananda
  • 333,661