Search subdirectories and find and print total files

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search subdirectories and find and print total files
# 1  
Old 08-22-2013
Search subdirectories and find and print total files

Hi All,

I have a folder name lets say path/to/folder/CUSTOMER and under this i have several folders and each of these subfolder have serveral subfolders and so on and at some point i will have a folder name called "FTP_FILES" .

I need to search for these folders named "FTP_FILES and then print the path and number of *.txt files in it.

I have the following code by which i am able to find the folder and list *.txt the files but how do i print the count of file in each line.

find ./CUSTOMER -name 'FTP_FILES' -print0 | xargs --null ls *.txt

Output desired..

PATH of the FTP_FILES folder :
Number of *.txt files :

Please help
# 2  
Old 08-22-2013
Hint: try using -type d option for directory
# 3  
Old 08-23-2013
Thanks for you reply, I tried using -type d option but i'm getting the same result as before. my above command actually is finding the folder and the .txt files but i also the number of .txt files in each FTP_FILES directory. And also, i see "total 31088" in one of the directories where there is only one file. Can you please help me with this. I need to find .txt files in all these folders and print the count of .txt files.

find ./CUSTOMER -type d -name 'FTP_FILES' -print0 | xargs --null ls -l

total 0

total 0

total 31088
-rw-r--r-- 1 user group 31832920 Aug 10 18:25 GRUN_IN_ALA_080813_105011.txt

total 0

total 0

# 4  
Old 08-23-2013
Try this for finding the file count:
find ./CUSTOMER -type d -name 'FTP_FILES' -print 0 | ls -l *.txt | grep ^- | wc -l

# 5  
Old 08-23-2013
Thank you, I tried your suggestion below but i'm getting result as "1"

find ./CUSTOMER -type d -name 'FTP_FILES' -print0 | ls -l *.txt | grep ^- | wc -l

But when i run the below i get "32" !!

find ./CUSTOMER -type d -name 'FTP_FILES' -print0 | xargs --null ls -l | grep ^-|wc -l

Also, i just realised that in some FTP_FILES folders there are sub-directories named by date and the actual files are in the date directories. The above command just list the directories.. but i need those files to be displayed as well. i know i might be asking some basics here sorry i'm still learning.
# 6  
Old 08-24-2013
So your requirement is to search for the FTP_FILES folder inside a given folder, and to traverse through all sub-folders in the FTP_FILES folder that is returned to find out *.txt files?
# 7  
Old 08-26-2013
Yes Sir, find a FOLDER named FTP_FILES and show me all files actually (not just *.txt) and if a sub-directory exixts under FTP_FOLDER then show the files from those sub-directories as well.

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use ls or find for search of subdirectories?

(5 Replies)
Discussion started by: jhsinger
5 Replies

2. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

3. 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

4. Shell Programming and Scripting

Find *.tar files under all subdirectories

Hi there, I'm new to shell scripting... I've a situation like to find *.tar files under all subdirectories in "/home/abcd" and i used the below, find /opt/lhapp ! -name "temp" | more the above works fine.. Now don't need search few direcotries like "/home/abcd/aaaa",... (15 Replies)
Discussion started by: skcvasanth
15 Replies

5. Shell Programming and Scripting

Search and find total count from multiple files

Please advice how can we search for a string say (abc) in multiple files and to get total occurrence of that searched string. (Need number of records that exits in period of time). File look like this (read as filename.yyyymmdd) a.20100101 b.20100108 c.20100115 d.20100122 e.20100129... (2 Replies)
Discussion started by: zooby
2 Replies

6. Shell Programming and Scripting

How to find files only inside the subdirectories only?

Hi I have a directory with two subdirectories and also have a code like below to search files modified in last 2 minutes. # ls hello080909.txt inbox outbox # find . -type f -mmin +2 ./inbox/hello2080909.txt ./outbox/hi0080909.txt ./hello080909.txt The above code just searches and... (3 Replies)
Discussion started by: Tuxidow
3 Replies

7. UNIX for Dummies Questions & Answers

search for files in subdirectories

Hi! I want to find files located in subdirectories. I have tried ls -R | grep myfile but this won't tell me where the file is, only that it is there. Any one have a better idea? Thanks, --Euclid (3 Replies)
Discussion started by: euclid3628800
3 Replies

8. Shell Programming and Scripting

Find files ignoring subdirectories

Hi guys, I am searching some files not equal to the pattern with this command find ! -name "PATTERN" -type f but my problem is the find command because he also search inside subdirectories and that's the thing i don't want that. Is there any comand to ignore the directories... (4 Replies)
Discussion started by: osramos
4 Replies

9. Shell Programming and Scripting

search files in a directory and its subdirectories

Hello my friends, I need to write a simple shell bad file :D that search and delete a file it's name 'Microsoft.txt' in the current directory and its subdirectories? So can you help to guide me how i can write this shell, Just give me the beginning :o thank you. (1 Reply)
Discussion started by: Net-Man
1 Replies
Login or Register to Ask a Question