I have been annoyed by the fact that I couldn’t easily print file count for all of the folders in certain directory. Most of the time I just want to see what space each folder is using (du -hs *) but there are times when I need to know how many files are in each folder (checking cache folder, session folders etc).  So I whipped together a command line which does just that for me:
for i in `find -maxdepth 1 -type d`; do echo -n $i " ";find $i|wc -l; done
I am sure there are many different ways to show file count for each folder in a directory and I am curious to see what people do so please do post comments with what you do.
Above command is pretty simple and can be expanded to do whatever you need. For example, you can throw it into a bash script and be able to pass parameters. For example: count_files /home/ In this case your command line would look like:
for i in `find /home/ -maxdepth 1 -type d`; do echo -n $i " ";find $i|wc -l; done
only difference would be that /home/ would be argument you passed and therefore will be $1. Here is a sample script for above example:
#!/bin/bash
for i in `find $1 -maxdepth 1 -type d`; do
echo -n $i " ";
find $i|wc -l;
done
————————————-
DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.
ls -lR | grep -B 1 -e “^total “
Thanks Scott but that gives disk usage for that particular folder which is not what I was looking. I was looking # of files within each folder under specific directory.
find . -maxdepth 2 -type f | awk -F/ ‘{ print $2 }’ | uniq -cd
The cost of enrolled today is indeed high that nearly everyone has to
adopt out student loans to drag it well bags on sale the proof is underneath the hood the internal components
fit together well inside the truth and so are apple-labeled.
If some one wishes expert view about blogging and site-building then i suggest him/her to visit this
blog, Keep up the pleasant job.
However, you are not alone on the island, there are rogue
bosses who need to rework your paradise of their
space staff Thurs.
Thats a really grat solution, it is memory-firendly, I like it.
Hi there, You’ve done a great job. I will definitely digg it and personally
suggest to my friends. I am confident they’ll be benefited from this site.
Octavia RS to najciekwsze auto czeskiego producenta.
Tworzymy serwis gdzie dyskutujemy o u?ywaniu Skody Octavia.
Je?eli równie? je?dzisz Skod? Octavia, do??cz do nas na http://www.Octavia.team
I have checked your website and i have found some duplicate content, that’s why
you don’t rank high in google’s search results, but there is a tool that
can help you to create 100% unique articles, search for; Boorfe’s
tips unlimited content
If some one wants expert view about running a blog afterward i advise him/her to pay a visit
this web site, Keep up the nice work.
At this time I am ready to do my breakfast, later than having
my breakfast coming yet again to read further news.
I think everything posted made a bunch of sense.
However, consider this, suppose you wrote a catchier post title?
I mean, I don’t wish to tell you how to run your website,
but suppose you added a headline that makes people want more?
I mean How do you print number of files for each folder in a directory [Linux] |
Technology: Learn and Share is a little plain. You could glance at
Yahoo’s front page and see how they create article titles to get viewers interested.
You might try adding a video or a pic or two to get readers excited about what you’ve got to say.
In my opinion, it would bring your blog a little livelier.
Great blog you have got here.. It’s difficult to find good quality writing like yours these days.
I really appreciate individuals like you! Take care!!