that would give me the entire number of files in the dir and recursivly as a single interger. not per directory basis i.e.
Directory Number of Files (incl sub dirs)
/var 112312
/etc 35210
and so on
but thanks for responding tho
---------- Post updated at 11:20 AM ---------- Previous update was at 11:14 AM ----------
I have found this command that works on Linux (RHEL5) but doesnt work on Solaris and also is too granular and indicates the size of each sub dir and doesnt just give me the total instead:
find . -type f | awk '{dir=gensub(/(.+\/).+/,"\\1","g",$0); dir_list[dir]++} END {for (d in dir_list) printf "%s %s\n",d,dir_list[d]}' | sort
Meth: thats good! but is there a way that it can just give my the total number of files within the dir instead of each one? group them together ie. from root: /var 100234 which includes all of /var subdirs. /etc 1323423 which includes all /etc subdirs.
Jim: I keep getting an error with your awk version:
bash: syntax error near unexpected token `(i'
syntax error near unexpected token `('
This would seem to be closer to your requirement. First find the names of the directories then count the number of files (excluding anything which is not a file) in each top level directory. If you are counting files in areas like /usr and /var it is usually necessary to stop "find" following links into other filesystems.
#!/someposixsh
# number of regular files in directory
currdir=$PWD
for dir in $(find . -type d)
do
cd $currdir/$dir
files=$( find . -maxdepth 1 -type f | wc -l )
echo "$files $dir"
done | sort -k 1,1nr
echo ____________________________________________________________________
# number of regular files in directory+subtree
cd $currdir
for dir in $(find . -type d)
do
cd $currdir/$dir
files=$( find . -type f | wc -l )
echo "$files $dir"
done | sort -k 1,1nr