On 2/10/23 23:47, SCOTT FIELDS wrote:
> I'm looking to get the number of files in each directory under a given path
> But only the top level of each directory (don't include files/directories from
> subdirectories in each processed directory)
>
> Example from your statement:
>
> # du --inodes -d 0 --all /usr
> 119613 /usr
>
> In this case, the number of entries directly within /usr is 15 (files, directories, etc), but this is reporting all
the files that exists within /usr and all other subdirectories.
>
> A script that does what I mean is fairly simple but hardly a simple one liner.
>
> --
>
> for directory in $(find <directory> -type d); do echo "$(ls -a $directory \
> | sed '/^\.$/d;/^\.\.$/d'| wc -l) $directory"; done
I see. du(1) traverses the whole directory hierarchy, so that's not wanted
anyway.
And --max-depth only changes which levels get printed and which not).
One could of course try to work with an --exclude pattern, but that's awkward.
Your direction with find(1) looks better - but with the -mindepth and -maxdepth
option:
find /usr -mindepth 1 -maxdepth 1 -printf x | wc -c
12
Does this come closer to what you want to achieve?
Have a nice day,
Berny