Number of files with *.something


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Number of files with *.something
# 1  
Old 03-28-2013
Number of files with *.something

I am trying to find the number of files that are of sas files. so I can do

find . -name '*.sas'

but I want to know how many. So what is the command to find so.
# 2  
Old 03-28-2013
why do that?

use ls -ltr *.sas | wc -l
# 3  
Old 03-28-2013
find is recursive, it will find them inside folders too if wished. You can tack wc -l onto it in the same way to get the number.
# 4  
Old 03-28-2013
Thanks for the replies

ls -ltr -r *.sas | wc -l

only looks at the current location I think. I am trying to find something recursive like find where it will also look into the sub directories and include them to the count.
# 5  
Old 03-28-2013
If you're going to throw away the pathnames, and if the only find implementations to be used support -printf, you can use that to emit nothing but a single newline character per file found. If there are a lot of files, it might speed things up a bit.

Regards,
Alister
# 6  
Old 03-28-2013
Quote:
Originally Posted by yatici
Thanks for the replies

ls -ltr -r *.sas | wc -l

only looks at the current location I think. I am trying to find something recursive like find where it will also look into the sub directories and include them to the count.
You can tack | wc -l onto the end of the find command as well, as already stated.
# 7  
Old 03-29-2013
Quote:
Originally Posted by PikK45
why do that?

use ls -ltr *.sas | wc -l
As an aside, the flags to ls serve no purpose here. And, a newline is a valid filename character. So, if any filename has one and since wc -l counts newlines, one might get wrong results.

Alister's solution (as always) is the most elegant:
Code:
find . -name '*.sas' -printf '\n'|wc -l


Last edited by elixir_sinari; 03-29-2013 at 01:10 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print number of lines for files in directory, also print number of unique lines

I have a directory of files, I can show the number of lines in each file and order them from lowest to highest with: wc -l *|sort 15263 Image.txt 16401 reference.txt 40459 richtexteditor.txt How can I also print the number of unique lines in each file? 15263 1401 Image.txt 16401... (15 Replies)
Discussion started by: spacegoose
15 Replies

2. Shell Programming and Scripting

List files with number to select based on number

Hi experts, I am using KSH and I am need to display file with number in front of file names and user can select it by entering the number. I am trying to use following command to display list with numbers. but I do not know how to capture number and identify what file it is to be used for... (5 Replies)
Discussion started by: mysocks
5 Replies

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

4. Shell Programming and Scripting

List files only when a certain number of files match

Hi, I have many files named CCR20110720011001.CTRD CCR20110720011501.CTRD CCR20110720012001.CTRD CCR20110720012501.CTRD CCR20110720021001.CTRD ... (9 Replies)
Discussion started by: shadyfright
9 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. UNIX for Dummies Questions & Answers

How to reduce multiple files into a specific number of files

Can anyone please let me know how do I reduce files into a specific number of files by cat'ing files? For example: 15 files must be reduced to 1 or 5 or 9 (possible values 1 to 14) (5 Replies)
Discussion started by: aryanbelank
5 Replies

7. Red Hat

Number of files

Hi, we have one monut point /u01/abc/ under this moumt point we have files generated from august 2008 now i need to send a report that everry months how many files are generated and there used space like august month 100 files got created and they occupy 3 Gb of space . september... (2 Replies)
Discussion started by: rohitmathur11
2 Replies

8. AIX

Number of files

Hi, we have one monut point /u01/abc/ under this moumt point we have files generated from august 2008 now i need to send a report that everry months how many files are generated and there used space like august month 100 files got created and they occupy 3 Gb of space .... (1 Reply)
Discussion started by: rohitmathur11
1 Replies

9. UNIX for Dummies Questions & Answers

split files into specified number of output files

Hi everyone, I have some large text files that I need to split into a specific number of files of equal size. As far as I know (and I don't really know that much :)) the split command only lets you specify the number of lines or bytes. The files are all of a different size, so the number of... (4 Replies)
Discussion started by: Migrainegirl
4 Replies

10. UNIX for Dummies Questions & Answers

total number of files which have "aaa" in files whose names are File*_bbb*

I am getting the list of all the files which have "aaa" from files whose name is File*_bbb*. grep -l "aaa" File*_bbb* But I want to count the number of files. That is I want the total number of files which have "aaa" in files File*_bbb* If I run the following for getting number of... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies
Login or Register to Ask a Question