I would like to recursively search a directory tree and list the number of files available in each folder that have a name corresponding to a given string. In effect, I would like to return results of:
ls -l | wc -l
for each folder I've identified via find
.
Code
The code below correctly lists number of files in each folder that name contains Magic Data string.
find /path/to/cool/stuff \
-maxdepth 4 \
-type d \
-name '*Magic Data*' \
-print0 | xargs \
--verbose \
-0 -I {} ls -l {}
I would like to expand it and pipe results of ls
to wc -l
.
Attempt
find /path/to/cool/stuff \
-maxdepth 4 \
-type d \
-name '*Magic Data*' \
-print0 | xargs \
--verbose \
-0 -I {} ls -l {} | wc -l
This fails and prints:
ls -l /path/to/cool/stuff/some/folders/Magic Data
ls -l /path/to/cool/stuff/some/folders2/Magic Data
Desired output
/path/to/cool/stuff/some/folders/Magic Data 29
/path/to/cool/stuff/some/folders2/Magic Data 30
Desired output would contain:
- Full path to the searched folder
- Output of
wc -l
, which in this case reflects count of non-hidden files