LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-02-2004, 07:22 PM   #1
ridertech
Member
 
Registered: Dec 2003
Location: Seattle, Washington
Distribution: Debian 'Sarge'
Posts: 85

Rep: Reputation: 15
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?
 
Old 06-02-2004, 10:26 PM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Number of files in directory bullium Linux - General 13 08-31-2011 08:50 AM
Maximum number of files in a directory neranjana General 14 05-13-2010 01:33 PM
finding size of total files in a directory blackzone Linux - Newbie 3 01-07-2005 03:01 AM
Finding number of CPUs. r_213 Linux - Networking 2 10-07-2004 11:48 PM
finding number of files in a directory pantera Programming 2 08-20-2004 10:17 AM


All times are GMT -5. The time now is 08:25 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration