Count files in every directory

Hi all,

I'm looking over all the internet for finding how to make a count of the files for every directory apart.. not a total result for the xx directories.

For example:
-dir1
file1
file2
-subdir1
-subdir2
file1
-subdir3
file1
-dir2
-dir3
file4

desired result from script:
dir1 - 2 files
dir 1 - subdir1 - 0 files
dir 1 - subdir2 - 1 file
dir 1 - subdir3 - 1 file
dir2 - 0 files
dir3 - 1 file

Is this possible? I can't find my way to make a script or make a command line.

Any help is welcome! Thanks

for x in `find /home/ -type d`; do echo -e "$x \c"; find $x -maxdepth 1 -type f | wc -l; done

Thanks balajesuri for your quick respons, it's going in the right way!

When executing that command line, he starts to scan every folder (what is good) but i receive after every folder this error :
-e /home//NAME find: 001-2187 The option -maxdepth is not valid.
0
-e /home//NAME/.eclipse find: 001-2187 The option -maxdepth is not valid.
0
-e /home//NAME/.eclipse/RSE find: 001-2187 The option -maxdepth is not valid.
0

any idea what to do for fixing this?

Read the find FAQ here advanced/complex uses of the find command - The UNIX and Linux Forums

See if this helps:

for x in `find /home/ -type d`; do echo -e "$x \c"; find $x -type f | grep -vc "^$x/[^/]*/.*"; done

Many thanks Balajesuri!!!
This is what i wanted. Finally after 3 days searching on the inet!

If i just want to creat an output for this i just use this code right?

for x in `find /home/ -type d`; do echo -e "$x \c"; find $x -type f | grep -vc "^$x/[^/]*/.*"; done   >   /qsys.lib/nboghman.lib/output.file/output.mbr

Yes of course, and please learn the art of using code tags.

Ok sorry didn't know that. I'm new here on this forum.

Is it also possible to have the folder with the most files on top and the folder with the lowest files at the bottom?

That is not a very robust solution. It's more complicated than it needs to be; it's not very portable (because of the echo); and, it will break on directory names with shell, echo escape, or basic regular expression metacharacters.

A better approach:

find . -type f | sed 's@/[^/]*$@@' | sort | uniq -c

Regards,
Alister

Thanks Alister,

It does show me all the files form the specified folder i'm asking but it wont tell me how many files are in for example : dir 1 subdir 1 and dir 2 and dir 3 subdir 1, 2 and 3.
It just gives me a list of all the files in every dir / subdir
Any solution?