I have lots and lots of files in a series of directories, and would like a nicely formatted list of how many files are in each directory.
The directories are ordered thus: Parent directories named A, B, ... H, I. Under each of these, there are from 1 to 7 directories named 001, 002, ... 007. In these directories, the files I'd like a count of files.
What I'm hoping for, is something like this:
... C/003 122 C/004 45 C/005 462 D/001 215 E/001 98 E/002 323 ...
I'm thinking a tab between directory-name and count. It doesn't matter if the count is left or right justified.
What I've done myself is basically this:
( for i in */* do echo ">>> $i" ls "$i" | wc done ) > file_count
The result is something like this:
... >>> F/002 30 30 234 >>> F/003 120 120 1322 >>> G/001 78 78 620 ...
Obviously, not bad... and if I replaced
wc -l and removed the ">>>" it would be even better - except that each "record" would be over two lines rather than one.
So what I need, is some
sed (or whatever - is there a simpler tool for joining two lines than those two?) magic to join the two-and-two lines into one.
However, if there is a more direct approach (shell-script, perl, python, some really dark sed & awk magic) that could make a list in "one go", that would be even better...