LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   finding the number of files in each directory (https://www.linuxquestions.org/questions/programming-9/finding-the-number-of-files-in-each-directory-189020/)

ridertech 06-02-2004 07:22 PM

finding the number of files in each directory
 
I'm trying to find the number of files in each directory, but I can only get the overall total. My directory structure is as follows: /music/artist/album/song.mp3

I've created a list of each song in each album using...
ls -l /music/*/* > music_dump

Ultimately, I'd like to know which albums contain 13 songs, but I can't even figure out how to count each album. I've tried piping wc -l to the end, but that returns the total number of all songs.

Does not work...
ls -l /music/*/* | wc -l

Any ideas?

crabboy 06-02-2004 10:26 PM

Not completely accurate, but it's a start without getting complicated. I had to add a hack to treat directory names with single ticks and spaces, you may find that there are other characters the shell does not like.

Code:

#!/bin/sh

IFS='
'
for i in `find . -type d`; do
  DIRNAME=`echo $i | sed "s/'/\\'/g"`
  echo "Directory $i has [`ls $DIRNAME | wc -l`] songs"
done



All times are GMT -5. The time now is 09:11 AM.