Show directory tree for matching directory names

0

I know that tree allows for pattern matching, but that only works for files inside directories. Let's say i have a folder structure looking like that:

➜  test tree
.
├── testdir1
│   ├── file1
│   └── file2
├── testdir2
│   ├── file1
│   └── file2
├── testdir3
│   ├── file1
│   └── file2
├── testdir4
│   ├── file1
│   └── file2
├── testdir5
│   ├── file1
│   └── file2
├── thatdir
│   ├── file1
│   └── file2
└── thatdir2
    ├── file1
    └── file2

And i want tree to only display contents of folders starting with that displayed in tree. I put together a bootleg zsh script that does what i needed:

for i in that*; tree $i;

output:

➜  test for i in that*; tree $i;
thatdir
├── file1
└── file2

0 directories, 2 files
thatdir2
├── file1
└── file2

However, I wondered if there is a better way of doing that instead of mindlessly putting a script over something instead of properly utilizing the tool (Also the formatting is a bit broken since command is executed multiple times)

w1kl4s

Posted 2018-10-26T12:33:05.963

Reputation: 15

Answers

1

tree that* should do what you want and is simpler

maoizm

Posted 2018-10-26T12:33:05.963

Reputation: 739

2Honestly i'm an idiot – w1kl4s – 2018-10-26T12:57:18.477

@w1kl4s ) no we'd rather say "less experienced user" as per local standard of conduct. Frankly there are a lot of areas where I feel exactly the same – maoizm – 2018-10-26T12:59:39.190

1"Failure is the key to success; each mistake teaches us something." - said someone, at some point in time... – spikey_richie – 2018-10-26T13:12:44.000