UNIX - command to count number of files in subdirectories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers UNIX - command to count number of files in subdirectories
# 1  
Old 03-17-2014
UNIX - command to count number of files in subdirectories

I have a folder named test/ and under that I have multiple directories and in each of the directory I have multiple log files. I want to know how many files exists under each sub directory.

Code:
test
  |--quanrantine
    |--logfile1
    |--logfile2
  |--spooling
    |--logfile1
    |--logfile2
    |--logfile3
    |--logfile4
  |--uploading
    |--logfile1
    |--logfile2
  |--staging
    |--logfile1

---------- Post updated at 02:06 PM ---------- Previous update was at 02:02 PM ----------

this command helped ..

Code:
$ for i in `ls | awk '{print $1}'` ; do p=`ls -lR $i/* | wc -l`; echo "$i:$p"; done;
quarantine:5
spooling:5
staging:98300
uploading:6540

# 2  
Old 03-17-2014
I did not test try something like...
Code:
cd test
find . -type -d | while read dirname
do
        count=`find ${dirname} -type f | wc -l`
        echo "${dirname}:${count}"
done

# 3  
Old 03-17-2014
Alternatively, most versions of Linux have tree: tree -d test

When you post a question like this it helps enormously to tell us what UNIX your are using, along with your current shell. My suggestion of tree was a guess.
# 4  
Old 03-17-2014
The start dirs can be done with echo
Code:
for i in *; do p=`find "$i" -type f | wc -l`;  echo "$i":"$p"; done

# 5  
Old 03-17-2014
Another approach using find and awk:
Code:
find test/ -type f | awk -F'/' '
{
        $NF = ""
        A[$0]++
}
END {
        for ( k in A )
                printf "%-50s%10d\n", k, A[k]
}' OFS='/'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count number of files

Hi All! I need to have a script that counts the number of files arriving in a landing directory, them some app pick these files to be processed and load to a DB. But this process is so fast that I am not able to count all the files arriving on a landing directory. Please can you help? My... (6 Replies)
Discussion started by: fretagi
6 Replies

2. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

3. UNIX for Dummies Questions & Answers

Rename a large number of files in subdirectories

Hi, I have a large number of subdirectories (>200), and in each of these directories there is a file with a name like "opp1234.dat". I'd like to know how I could change the names of these files to say "out.dat" in all these subdirectories in one go. Thanks! (5 Replies)
Discussion started by: lost.identity
5 Replies

4. UNIX for Dummies Questions & Answers

Command for total number of files (and size) across subdirectories?

Hi all... I have a directory called dbrn. This directory contains an unknown number of subdirectories which in turn contain an unknown number of files. What I want to know is: How many files with extention .ABC can be found in /dbrn across all subdirecties, and what is the total size for... (9 Replies)
Discussion started by: Beun
9 Replies

5. UNIX for Dummies Questions & Answers

count files and subdirectories under /software

Dear All i need to find to total number of the files and subdirectories under /software i issue this command find /software/* -print | wc -l but i need another command to know how many files and subdirectories . (3 Replies)
Discussion started by: thecobra151
3 Replies

6. Shell Programming and Scripting

how can i find number of lines in files & subdirectories

how can i find number of lines in files & subdirectories ? (3 Replies)
Discussion started by: pcbuilder
3 Replies

7. UNIX for Dummies Questions & Answers

Count number of files in directory excluding existing files

Hi, Please let me know how to find out number of files in a directory excluding existing files..The existing file format will be unknown..each time.. Thanks (3 Replies)
Discussion started by: ammu
3 Replies

8. UNIX for Dummies Questions & Answers

Unix command to count the number of files with specific characters in name

Hey all, I'm looking for a command that will search a directory (and all subdirectories) and give me a file count for the number of files that contain specific characters within its filename. e.g. I want to find the number of files that contain "-a.jpg" in their name. All the searching I've... (6 Replies)
Discussion started by: murphysm
6 Replies

9. UNIX for Dummies Questions & Answers

unix command to cound the number of files in a folder

Hi All Can some one help me out. Please tell the unix command to cound the number of files in a folder. Ungent please# Thanks manas (6 Replies)
Discussion started by: manas6
6 Replies

10. UNIX for Dummies Questions & Answers

Count number of files in subdirectories

Hello, I am new to unix and would like to have a count of all the files in the current directory as well as all the files in a subdirectory. The command I used was ls -R | wc -l but the number returned wasn't correct. Can someone please help? Thanks (2 Replies)
Discussion started by: cbeverly
2 Replies
Login or Register to Ask a Question