homepage Welcome to WebmasterWorld Guest from 50.19.206.49
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
count files in a directory and each subdirectory
jjc_mn




msg:3087665
 5:53 pm on Sep 18, 2006 (gmt 0)

Has anybody written a short shell script that could be launched in any directory and it would list all the subdirectories and how many files in each specific subdirectory?

 

lammert




msg:3087671
 5:58 pm on Sep 18, 2006 (gmt 0)

Seems to be a popular topic:

[webmasterworld.com...]

jjc_mn




msg:3087700
 6:15 pm on Sep 18, 2006 (gmt 0)

That was a total count. I was looking for directory by directory file count so you could see how many files were in any subdirectory.

This will have to be a shell script in a for loop, not a quick one liner becuase the loop will first have to identify the subdirectory, then do the count, and then print subdirectory name and file count to the screen.

jjc_mn




msg:3087795
 7:46 pm on Sep 18, 2006 (gmt 0)

Couldn't wait. wrote it myself. Here it is in case anybody else finds themself with a Unix box running out of space.

#Counts files in subdirectories
date_stamp=`date +"%m%d%Y.%H%M%S"`
temp_file="temp.$date_stamp.txt"
find . -type d > $temp_file

exec 3< $temp_file
until [ $done ]
do
read <&3 myline
if [ $?!= 0 ]; then
done=1
continue
fi
dircount=`find $myline"/." \( -name . -o -prune \) -type f ¦ wc -l`
echo "$dircount"$myline
done
rm $temp_file
#EOF

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved