Count Files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count Files
# 1  
Old 09-17-2010
Count Files

I was wondering if anyone could help me with this problem:

Write a script called countFiles that takes two arguments, the initial directory and the number of levels and returns the count of all files (including directories) in the directories and subdirectories up to the number of levels.

*** This script must use loop(s), traverse directories, count files in a single directory, have an error detection, and determine that a file is a directory. (Use find if you would like)
# 2  
Old 09-17-2010
I have findutils 4.2.2 and the following counts everything..

Code:
 find $1 -maxdepth $2 | wc -l

This User Gave Thanks to rajamadhavan For This Post:
# 3  
Old 09-17-2010
and if i dont have findutils 4.2.2, is there another way to solve this problem?
# 4  
Old 09-17-2010
Quote:
Originally Posted by clammy
I was wondering if anyone could help me with this problem:

Write a script called countFiles that takes two arguments, the initial directory and the number of levels and returns the count of all files (including directories) in the directories and subdirectories up to the number of levels.

*** This script must use loop(s), traverse directories, count files in a single directory, have an error detection, and determine that a file is a directory. (Use find if you would like)
looks like homework.
# 5  
Old 09-17-2010
yep it is homework,

i think i got it figured out for the most part:




counter=0

for file in * ; do
echo $file at $counter
let "counter+=1"
done

echo "COUNTER:$counter"

Last edited by clammy; 09-17-2010 at 03:45 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

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

3. UNIX for Dummies Questions & Answers

How to count different id from a files?

Hi Guys, Please help for counting different task_id:- file name is: sms_push_123.ac:011:045 file records: Now we need to output like: (1 Reply)
Discussion started by: aaditya321
1 Replies

4. Shell Programming and Scripting

Count for only todays files.

Hi, I unable to find the direct command get the total count for the below files with today date. ls -lrt c90.txt n5.txt t1.txt k3.txt h9.txt s1.txt n2.txt a123.txt -rw-rw-r-- kkk klkl 980 Apr 26 19:00 c90.txt -rw-rw-r-- kkk klkl 80 Apr 26 19:00 n5.txt -rw-rw-r-- kkk klkl 12890 Apr 26... (3 Replies)
Discussion started by: onesuri
3 Replies

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

6. Shell Programming and Scripting

Count todays created files and old files

Hello experts, I used following approach to get listing of all files of remote server. Now I have remote server file information on same server. I am getting listing in the output.txt I want to count today's created files and old files. I want to compare the numbers... (11 Replies)
Discussion started by: dipeshvshah
11 Replies

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

8. Shell Programming and Scripting

Display the count of files

I am new to shell programming. Can anyone help me out with anyone of these? Display a count of the number of regular files, the number of symbolic links, the number of sub-directories, the number of block-special files, and the number of character-special files in the directory. I don't... (4 Replies)
Discussion started by: wayne1411
4 Replies

9. Shell Programming and Scripting

count of files

How to count the number of files in a directory. Thanks Mahalakshmi.A (13 Replies)
Discussion started by: mahalakshmi
13 Replies
Login or Register to Ask a Question