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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Unix command to count the number of files with specific characters in name
# 1  
Old 05-06-2010
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 done on forums have only been for code counting the total number of files in a directory. I need to count only certain files within that directory.

Thanks!
SM
# 2  
Old 05-06-2010
Does the following display a count of your files?
Code:
ls *-a.jpg | wc -l

# 3  
Old 05-06-2010
Maybe
Code:
find . -name "*-a.jpg" | wc -l

Edit: this command looks into subdirectories as well.

Last edited by pseudocoder; 05-06-2010 at 03:58 PM..
# 4  
Old 05-06-2010
Quote:
Originally Posted by joeyg
Does the following display a count of your files?
Code:
ls *-a.jpg | wc -l

Helo, In Solaris 10 it didnt not work for me, or even

ls -lR *-a.jpg

Code:
find . -name "*-a.jpg" | wc -l

works well
# 5  
Old 05-06-2010
MySQL

Quote:
Originally Posted by pseudocoder
Maybe
Code:
find . -name "*-a.jpg" | wc -l

That seems to have worked. ... though my results using that code and searching manually in the Finder (Mac OS) are greatly different. The finder is only showing 275 items while the Unix code is showing 510. Could there be that many hidden files? Is there a way to exclude hidden files?

Just using this smaller folder as a test. Been trying to find a solution since the Mac Finder only shows results up to 10,000 and I have several directories with results well beyond that. Thanks.
# 6  
Old 05-06-2010
Quote:
Originally Posted by murphysm
Could there be that many hidden files?
Maybe... I don't know.

Quote:
Originally Posted by murphysm
Is there a way to exclude hidden files?
IMHO no, but I may err.

Looks like you will have to manually compare the results and see what's going on.
# 7  
Old 05-07-2010
Quote:
Originally Posted by murphysm
Is there a way to exclude hidden files?
If "hidden" means "file name starting with a dot", filtering should be possible, I daresay:

Code:
[house@leonov] ls -1A | grep '.file'
.hidden.file
test.file
that.file
this.file
[house@leonov] find . -name "*.file" | wc -l
4
[house@leonov] find . -name "[[:alnum:]]*.file" | wc -l
3

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to count number of characters of wc -l output?

I want count number of characters / find the length of the 'wc -l' output This is the command bash-3.2$ gzcat /home/sid/file1.dat |wc -l 830752 So final out I want is 6 i.e lenght of 830752 I tried with awk bash-3.2$ gzcat /home/sid/file1.dat |wc -l | awk '{print length ($0)... (3 Replies)
Discussion started by: sidnow
3 Replies

2. UNIX for Dummies Questions & Answers

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. test |--quanrantine |--logfile1 |--logfile2 |--spooling |--logfile1 ... (4 Replies)
Discussion started by: ravikirankethe
4 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

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

5. Shell Programming and Scripting

how to count how many subdirectory containing more than a certain number of specific file type

hi I want to write a script which count the number of subdirectories in the current root directory that contain more than a specified number of files of a specific type. Is there an easy way to do this? Thanks Robert (2 Replies)
Discussion started by: piynik
2 Replies

6. Shell Programming and Scripting

Count number of characters in particular column

Hi i have data like abchd 124 ldskc aattggcc each separated by tab space i want to count number of characters in 4th column and print it in new column with tabspace for every line can anyone help me how to do it. Thanks. (3 Replies)
Discussion started by: bhargavpbk88
3 Replies

7. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

8. Shell Programming and Scripting

How to extract specific data and count number containing sets from a file?

Hello everybody! I am quit new here and hope you can help me. Using an awk script I am trying to extract data from several files. The structure of the input files is as follows: TimeStep parameter1 parameter2 parameter3 parameter4 e.g. 1 X Y Z L 1 D H Z I 1 H Y E W 2 D H G F 2 R... (2 Replies)
Discussion started by: Daniel8472
2 Replies

9. Programming

Count the number of repeated characters in a given string

i have a string "dfasdfasdfadf" i want to count the number of times each character is repeated.. For instance, d is repeated 4 times, f is repeated 4 times.. can u give a program in c (1 Reply)
Discussion started by: pgmfourms
1 Replies

10. Shell Programming and Scripting

count characters in specific records

I have a text file which represents a http flow like this: HTTP/1.1 200 OK Date: Fri, 23 Jan 2009 17:16:24 GMT Server: Apache Last-Modified: Fri, 23 Jan 2009 17:08:03 GMT Accept-Ranges: bytes Cache-Control: max-age=540 Expires: Fri, 23 Jan 2009 17:21:31 GMT Vary: Accept-Encoding ... (1 Reply)
Discussion started by: littleboyblu
1 Replies
Login or Register to Ask a Question