2

I'm creating a script that generates a project folder into another folder along with some other module folders. I want to show how the generated project folder structure looks in the final tree but avoid the expansion of all other folders so the visualization is clearer.

For instance, this is what happens if I do tree alone:

.
├── CMakeLists.txt
├── cfg
│   ├── hsm_engine_cfg.h
│   ├── osal_rtos_defs.h
│   ├── system_events.h
│   ├── system_tasks.h
│   ├── system_trace_cfg.h
│   └── test_delete_cfg.h
├── hsm-engine
│   ├── CMakeLists.txt
│   ├── README.md
│   ├── component.mk
│   ├── docs
│   │   ├── HSM-Engine.mdj
│   │   ├── images
│   │   │   ├── choiceState.png
│   │   │   ├── inconditionalTransition.png
│   │   │   ├── inconditionalTransitionTwoEvents.png
│   │   │   ├── inconditionalTransitionTwoEventsOneGuard.png
│   │   │   ├── inconditionalTransitionWithActions.png
│   │   │   ├── simpleStateEmpty.png
│   │   │   ├── simpleStateEntry.png
│   │   │   ├── simpleStateEntryDo.png
│   │   │   └── simpleStateEntryExit.png
│   │   └── readme.md
│   ├── hsm_engine.c
│   ├── hsm_engine_cfg.h.txt
│   ├── include
│   │   ├── hsm_engine.h
│   │   ├── hsme_history_entry_struct_macro.h
│   │   ├── hsme_hsm_handler_macro.h
│   │   ├── hsme_state_transitions_macro.h
│   │   ├── hsme_states_array_macro.h
│   │   └── hsme_states_enum_macro.h
│   └── tools
│       ├── hsm-parser
│       └── hsm-parser.exe
├── osal
│   ├── CMakeLists.txt
│   ├── FreeRTOSConfig.h.txt
│   ├── Kconfig
│   ├── README.md
│   ├── component.mk
│   ├── include
│   │   ├── osal.h
│   │   ├── osal_events.h
│   │   ├── osal_task_sync.h
│   │   └── osal_tasks.h
│   ├── osal_events.c
│   ├── osal_rtos_defs.h.txt
│   ├── osal_task_sync.c
│   ├── osal_tasks.c
│   ├── system_events.h.txt
│   └── system_tasks.h.txt
├── test-delete
│   ├── CMakeLists.txt
│   ├── include
│   │   ├── test_delete_api.h
│   │   └── test_delete_event_id.h
│   ├── test_delete.c
│   ├── test_delete.h
│   └── test_delete_cfg.h.txt
├── test-gtest
│   ├── CMakeLists.txt
│   ├── README.md
│   └── test_delete_testsuite.cpp
├── test_delete_main.c
└── trace
    ├── CMakeLists.txt
    ├── Kconfig
    ├── README.md
    ├── component.mk
    ├── include
    │   ├── colors.h
    │   └── system_trace.h
    ├── system_trace.c
    └── system_trace_cfg.h.txt

As you can see, that's a lot of output and it is not clear to see the created folder in which I'm interested which is test-delete.

I tried with tree -P 'test-delete*|test_delete*' is really close to what I need. It gives:

.
├── cfg
│   └── test_delete_cfg.h
├── hsm-engine
│   ├── docs
│   │   └── images
│   ├── include
│   └── tools
├── osal
│   └── include
├── test-delete
│   ├── include
│   │   ├── test_delete_api.h
│   │   └── test_delete_event_id.h
│   ├── test_delete.c
│   ├── test_delete.h
│   └── test_delete_cfg.h.txt
├── test-gtest
│   └── test_delete_testsuite.cpp
├── test_delete_main.c
└── trace
    └── include

But it is still expanding all the folders which is not ideal. I'm looking for the correct tree configuration so I have this:

.
├── cfg
│   └── test_delete_cfg.h
├── hsm-engine
├── osal
├── test-delete
│   ├── include
│   │   ├── test_delete_api.h
│   │   └── test_delete_event_id.h
│   ├── test_delete.c
│   ├── test_delete.h
│   └── test_delete_cfg.h.txt
├── test-gtest
├── test_delete_main.c
└── trace

As you can see here. only cfg and test-delete folders are expanded, the rest is not. Is there a way to achieve this?

m4l490n
  • 175

2 Answers2

3

Assuming your file names don't contain newline characters, you could always do:

find . -path '*test[-_]delete*' | tree --fromfile /dev/stdin

Or

find . | grep 'test[-_]delete' | tree --fromfile /dev/stdin
  • Is there a way to do this for multiple folders with different names? For example, I want to get the tree structure for cruises and cruise_control, but my command only returns those for cruises : ```find . (-type f -and -path 'cruises' -or -path 'cruise_control') | tree --fromfile /dev/stdin
    
    
    – me.limes Jul 03 '22 at 19:26
0

If your goal to find files with 'test-delete' in the name, it would be better to use find:

find . -name test-delete*
White Owl
  • 5,129