awk command to find the count of files ina directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk command to find the count of files ina directory
# 8  
Old 07-19-2007
Quote:
Originally Posted by aajan
By doing so, it wil count the directories also my dear pal
You are right, that would include directories as well.

My awk command should do then ! Smilie

Thanks for pointing it out ! Smilie
# 9  
Old 07-19-2007
zsh:

with ...
Code:
set -- *(.D);num_files="${#@}"

.. and without dot files:

Code:
set -- *(.);num_files="${#@}"

# 10  
Old 07-19-2007
Quote:
Originally Posted by matrixmadhan
Code:
ls -1  |awk 'END{print NR}'

matrixmadhan,

Use ls -l instead of ls -1 because it fails with filenames with spaces.

Code:
ls -1 | wc -l

also fails.

Regards
# 11  
Old 07-19-2007
Quote:
Originally Posted by Franklin52
matrixmadhan,

Use ls -l instead of ls -1 because it fails with filenames with spaces.

Code:
ls -1 | wc -l

also fails.

Regards
Am sorry that ls -1 won't fail for files having spaces in their names

if you are using ls -l instead of ls -1 then explicitly you need to subtract 1 from the result, if you are directly operating ls -l on wc -l.
# 12  
Old 07-19-2007
Quote:
Originally Posted by matrixmadhan
Am sorry that ls -1 won't fail for files having spaces in their names

if you are using ls -l instead of ls -1 then explicitly you need to subtract 1 from the result, if you are directly operating ls -l on wc -l.
I'm sorry you're right, I was confused to see that there was 1 less with ls -1 but I forgot the first line of ls -l.

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Listing only the files under a directory from the result of find command

Hi, I have a main folder 'home'. Lets say there is a folder 'bin' under 'home'. I want to check the list of files under subdirectories present under the /bin directory created in the last 24 hours. I am using the following find command under home/bin directory: find . -mtime -1 -print ... (3 Replies)
Discussion started by: DJose
3 Replies

2. UNIX for Dummies Questions & Answers

[Solved] How to find particular files ina directory?

Hi, I am trying to write a script to find some files in a directory Example: if i have files like 2014-02-01_aaaa.txt 2014-02-01_bbbb.txt 2014-02-01_cccc.txt 2014-02-01_dddd.txt and some other files how can i just check to see if there four files exits or not i tried some thing like this... (5 Replies)
Discussion started by: vikatakavi
5 Replies

3. Shell Programming and Scripting

Find command to search files in a directory excluding subdirectories

Hi Forum, I am using the below command to find files older than x days in a directory excluding subdirectories. From the previous forums I got to know that prune command helps us not to descend in subdirectories. Though I am using it here, not getting the desired result. cd $dir... (8 Replies)
Discussion started by: jhilmil
8 Replies

4. Shell Programming and Scripting

awk command to compare a file with set of files in a directory using 'awk'

Hi, I have a situation to compare one file, say file1.txt with a set of files in directory.The directory contains more than 100 files. To be more precise, the requirement is to compare the first field of file1.txt with the first field in all the files in the directory.The files in the... (10 Replies)
Discussion started by: anandek
10 Replies

5. UNIX for Dummies Questions & Answers

command to find cksum of all files inside a directory?

I did this: ls -lrRt | grep ^* | cksum * but it is showing cksum of sub-directories. Thanks You Please use code tags when posting data and code samples, thank you. (3 Replies)
Discussion started by: ezee
3 Replies

6. Shell Programming and Scripting

Apply 'awk' to all files in a directory or individual files from a command line

Hi All, I am using the awk command to replace ',' by '\t' (tabs) in a csv file. I would like to apply this to all .csv files in a directory and create .txt files with the tabs. How would I do this in a script? I have the following script called "csvtabs": awk 'BEGIN { FS... (4 Replies)
Discussion started by: ScKaSx
4 Replies

7. Shell Programming and Scripting

print as well as count the files found by find command

I want the output of the find command to be printed and also the total files found by it. Can someone help in this. Obviously $ find . -type f | wc -l will not output the files found but only the count. I want both. There can be millions and trillions of files so dont want the output of find... (3 Replies)
Discussion started by: amicon007
3 Replies

8. Solaris

How to delete Directory and inside files using Find command

I am using the following Command to delete Directory with contents. But this command is deleting inside files only not directories. is there any change need in my command? find -type f -mtime +3 -exec rm -r {} \; Thanks (3 Replies)
Discussion started by: bmkreddy
3 Replies

9. UNIX for Dummies Questions & Answers

How to find the count of files in a directory

Hi Gurus WHat would be the command to check whether there is a file in particular path or not.. for ex: my file name is ExRate_20071501.csv I can have many files with same pattern but diffrentiated by date.. i have a process where i have to check if files exist in tht folder i have to... (5 Replies)
Discussion started by: sish78
5 Replies

10. AIX

Help Using Grep command to Find the string in the files in the root directory

I want to serch for a string in all the files in the root directory. i want the search to be limited to only the files in the directory i.e the search to be done only in the files not in the sub directory. the approaches tried are 1)grep "pattern string" this command was serching the... (3 Replies)
Discussion started by: Subbu_Angeline
3 Replies
Login or Register to Ask a Question