AWK Script - Count Files In Directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK Script - Count Files In Directories
# 1  
Old 01-23-2009
AWK Script - Count Files In Directories

Hey,

I'm very new to AWK and am trying to write a script that counts the number of files in all subdirectories. So, basically, my root has many subdirectories, and each subdirectory has many files.

How can I get the total count? I haven't been able to figure out how to loop through the directories to get the count of each directory and sum it all up. Any help is appreciated!

Thanks
Mike

My directory structure is like:

/root
/root/dir1
/root/dir1/file1
/root/dir1/file2....
/root/dir2
/root/dir3
/root/dir....
# 2  
Old 01-23-2009
You don't need awk...to get a directory tree, use
Code:
ls -R root

but to count them use
Code:
find /root -print

and then pipe the output into wc to count the number of lines, so
Code:
find /root -print | wc -l

Jerry
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

2. Shell Programming and Scripting

awk to compare files and count

I am trying to compare 2 files and output the results in two files. The lines that are the same output to concordant.txt while the lines that do not match output to discordant.txt. Is there a way to count the lines after specific text (#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT E1) in each... (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

awk - Compare files in two different directories

Hi, My script works fine when I have both input files in the same directory but when I put on of the input file in another directory, the output does not show up. SCRIPT: awk ' BEGIN { OFS="\t" out = "File3.txt"} NR==FNR && NF {a=$0; next} function print_77_99() { if... (3 Replies)
Discussion started by: High-T
3 Replies

4. Shell Programming and Scripting

Count files between multiple directories

Hi All, Everyday we will receive 33 files in our source directory(/prd/pk) with the current date. Once our jobs are completed all the 33 files immediately will be moved to backup folder (/prd/pk/backup). Now, I need to check between source file directory (/prd/pdk) and backup file directory... (3 Replies)
Discussion started by: suresh_target
3 Replies

5. Shell Programming and Scripting

List directories and count files inside

I'm trying to make a script that will list all directories under a selection as well as the number of files in each. I cannot get it to work under a symbolic link. The file structure is: XXX_20131127_001 dir01 (sym link) 2404x912 file.0000.xxx to ... (10 Replies)
Discussion started by: scribling
10 Replies

6. Shell Programming and Scripting

Script to count number of files in directories

Hi All! I would like to have a script that will count the number of files at the top of the hour of soome directories and mail the results to me. I was thinking on : a=`/directory/subdirectory/ | wc -l` echo "/directory/subdirectory :$a" b=`/another_dir/subdir/ | wc -l` echo... (12 Replies)
Discussion started by: fretagi
12 Replies

7. UNIX for Dummies Questions & Answers

Count of files and directories

Hi I have a jfs2 filesystem named /software in my aix 5.3 box. Please note that there are a lot of subdirectories under /software? I need to know the count of how many total files and directories are present under that mount point /software ? For example if by some commands we find that there... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

8. Shell Programming and Scripting

Count of files in directories

Hi, I have a requirement to find out the count of files in directories. I can do this very well by goind to each directory and then ls -lrt | wc -l. But I need to do it for hundreds of directories/sub-directories. I tried with this - for i in `ls -F | grep '/$'`; do `echo "$i"`| ls -lrt... (2 Replies)
Discussion started by: unx100
2 Replies

9. Solaris

Get Count of all files in all the directories

Hello, I am looking for a way to get the TOTAL COUNT of the files present in all directories(sub directories) under the root directory..The files can be of any type viz. txt, doc, html, wav, jpeg etc. If it has an extension, it has to be counted.. I want to run the script from the root directory.... (6 Replies)
Discussion started by: oniondosa
6 Replies

10. Shell Programming and Scripting

Bash and Awk for creating directories and moving files

I have a security system that FTPs the camera files to my machine, however I want to sort the pictures (taken every 30s) into directories by hour. Every picture uses the following file format. yymmddhhmmsstt.jpg (where tt is the milliseconds) I am thinking the for loop is best for file... (11 Replies)
Discussion started by: Kiint
11 Replies
Login or Register to Ask a Question