Given the following folder layout:
Current_folder
└── FolderA
| └── CMakeList.txt
| └── FolderAA
| └── CMakeList.txt
|
└── FolderB
| └── FolderBA
| | └── CMakeList.txt
| | └── FolderBAA
| | └── CMakeList.txt
| |
| └── FolderBB
| └── CMakeList.txt
|
└── FolderC
└── CMakeList.txt
└── FolderCA
└── CMakeList.txt
How can I use find
(or any other tool) to produce an output similar to:
Current_folder/FolderA/CMakeList.txt
Current_folder/FolderB/FolderBA/CMakeList.txt
Current_folder/FolderB/FolderBB/CMakeList.txt
Current_folder/FolderC/CMakeList.txt
Meaning that the search is stopped after a match with the literal "CMakeLists.txt" for each recursive folder branch respectively.
A shell function (untested):
You would do something like this:
This will print the file's path and
-quit
as soon as first file with matched name found from each path that feeding tofind "$path"
.αғsнιη's answer contains the correct solution with
find
, but if you have a lot of directories calling onefind
after another can be quite slow. If you want to make use of all your CPU cores and run thefind
processes in parallel I recommend GNUparallel
for the task:What worked for me was the following bash script:
@dessert's answer worked for the minimal example above as well. Using it on my actual folder structure (~4000 folders) it was still giving wrong results. I'm not sure why, to be honest.
When I tried @muru's solution it wouldn't stop executing. I guess the function calling itself isn't aborting properly? Not sure about the reason here either.
PS: In an actual CMake Project the file is actually called "CMakeLists.txt" (note the extra s in the end). I spotted this error only after answers were already provided.