counting files

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers counting files
# 1  
Question counting files

Which one line command can count and print to the screen the number of files containing "a" or "A" in their name
# 2  
Is this a homework question?
# 3  
Kristy sounds like one to me! Smilie

Edy there are many many ways of doing this...look into the piping the ls command into grep and then a sorting for the amount using wc - this is a very simple way of doing this and should set you out on the right path.

# 4  
Looks like a home ..........

ls |awk '{print$1}'|grep [a,A]|wc -l

# 5  
Originally posted by reddyb
Looks like a home ..........

ls |awk '{print$1}'|grep [a,A]|wc -l

ls |grep [a,A]|wc -l

the ls -l would not be needed and if you did the ls -l then the awk for the 1st field you would get the directory perms. if you insisted on using the ls -l tho you would need to awk for field 9 which would be the filename.

and deffinetly sounds like a hw question.

reddyb: did you edit the post or something the first time i looked at it i swear it said ls -l. if not my bad. but the awk is still not needed.
# 6  
Yes, You are right, I did edit it.
I want to make it generic so that you can grep on any column you want!


Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #997
Difficulty: Medium
The use of hypervisor technology by malware and rootkits installing themselves as a hypervisor below the operating system is known as hyperjacking.
True or False?

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Counting files without ls or wc

i need to write a shell script to "count the number of files in the current directory but without using either ls or wc command"..... please help! (1 Reply)
Discussion started by: lexicon
1 Replies

2. UNIX for Advanced & Expert Users

Counting files in a given directory

Hi all, Need some help counting files... :) I'm trying to count the number of files in a given directory (and subdirectories) which reportedly contains "thousands" of files. I'm using this: ls -R | wc -l However it's been an hour and looks like it's still running; there is no output... (18 Replies)
Discussion started by: verdepollo
18 Replies

3. Shell Programming and Scripting

Counting Files

In a script, how would I go about finding the number of files for the first parameter after my script name? For instance, my script name is and the folder I am checking is not the current working directory, lets say it's folder1. so I type folder1 This script below... (2 Replies)
Discussion started by: Confirmed104
2 Replies

4. Shell Programming and Scripting

Counting Files Containing Text

Hello Everyone, I'm trying to create a bash script that will count the number of files containing a certain keyword. The twist is that the keyword is found in a unix File and is part of a list. For example, the file DELETE may look like this: John Mike Dana The script will look for files... (4 Replies)
Discussion started by: jl487
4 Replies

5. UNIX for Dummies Questions & Answers

Counting rows in many files

I'm regularly counting the number of rows in a number of files. I need to know how many rows their are in all files together. Counting rows in one file I can handle, but how do I count rows in all at once? I'd be grateful for any answer. (7 Replies)
Discussion started by: DrZoidberg
7 Replies

6. Solaris

Counting up files

Hi, I have a load of if statements that look for files in a directory, I want to be able to count them up and the total files confirmed in an email? I ahve tried expr but i this does not work and it only reads in the first if and ignores the rest. Please see script, #!/bin/ksh ... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies

7. Shell Programming and Scripting

Help with counting files please

Hi all. If I have a unix directory with multiple files, lets say, I have some with .dat extensions, some with .txt extensions, etc etc. How in a script would I provide a count of all the different file types (so, the different extensions, I guess) in the directory?? So if I had: test.dat... (6 Replies)
Discussion started by: gerard1
6 Replies

8. UNIX for Dummies Questions & Answers

Counting lines and files

Hi experts, First of all thanks for all your help. How can i count the lines within a text file and send this number to another text file? And by the way how can i count the number of files inside a tape ("/dev/rtp") that as one pattern (Ex. "/CTA/") and send this number to a text file? I... (6 Replies)
Discussion started by: jorge.ferreira
6 Replies

9. UNIX for Dummies Questions & Answers

Counting Occurances in Two Files

I have two files I want to compare, one is a list of variables and the other is a text file COBOL program. Basically what I want to do is display only those variables that appear in the COBOL program only once. However I would also accept a count of each variable as it appears in the COBOL... (2 Replies)
Discussion started by: Keith Gergel
2 Replies