Piping results of 'ls' to 'find' using 'xargs'

I'm trying to get a count of all the files in a series of directories on a per directory basis. Directory structure is like (but with many more files):

/dir1/subdir1/file1.txt
/dir1/subdir1/file2.txt
/dir1/subdir2/file1.txt
/dir1/subdir2/file2.txt
/dir2/subdir1/file1.txt
/dir2/subdir2/file1.txt

So, I want my output to be something like:

dir1
4
dir2
2

To achieve this I tried:

ls -d1 dir* | xargs -n 1 find {} -type f | wc -l

but I get the following error message:

find: bad option dir1
find: path-list predicate-list
...

It appears that find is interpreting the directory passed by xargs as an option rather than a path-list.

Can anyone explain why please?

Thanks for taking the time to look.

Try this:

ls -d1 dir* | xargs -I {} find {} -type f | wc -l

Thanks "jlliagre" that makes it work.

However, seems I'm barking up the wrong tree as what I've done pipes ALL files in ALL directories to wc

In other words, it does the same as:

find dir1 dir2 -type f | wc -l

When what I really want is:

 
find dir1 -type f | wc -l; find dir2 -type f | wc -l

---------- Post updated at 11:57 AM ---------- Previous update was at 11:24 AM ----------

Somebody showed me how to do a for loop and I came up with this, which does what I wanted:

 
for dir in `ls -d dir*`; do echo $dir; find $dir -type f | wc -l; done

Thanks to all those who had a look.

Might be slightly simplified that way:

for dir in dir*; do echo $dir; find $dir -type f | wc -l; done

Another way:

#  find . | nawk -F"/" 'NF>2{t[$2]++}END{for (x in t){print x,t[x]}}'