Register
It is currently Sat Nov 01, 2014 5:43 am

need script to recurse directory tree and count files


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Apr 01, 2009 2:43 pm   

Joined: Wed Apr 01, 2009 2:37 pm
Posts: 1
Ideally I'd like to recurse a directory tree, and count the number of files per directory. I'm thinking output could be something like tree, but with file counts tagged to the end of each line.

Any help much appreciated.


Top
 Profile  
 PostPosted: Thu Apr 02, 2009 2:24 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Something like this might work, my Digital Unix find isn't really updated so the {} doesn't really show anything.
Might work better on a newer version.
Code:
find ./ -type d -exec sh -c 'echo -n $1:; ls $1 | wc -l | sed "s/^ *//"' {} {} \;


Replace ./ with the path you want to search :)

This will give you the output like this
./fredrik: 15
./fredrik/somedir: 20

And so on :)

Best regards
Fredrik Eriksson


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP